모든 챌린지
보통 0명 해결 정답률 0%

Two Nonattacking Knights

Count safe placements of two knights for each square board size.

For each board size k from 1 through n, count unordered pairs of distinct squares on a k by k board where two knights cannot attack each other. A knight moves two squares in one axis and one in the other.

. x . x .
x . . . x
. . K . .
x . . . x
. x . x .

K marks a knight and x its possible destinations, when those squares lie on the board. Swapping the two knights does not create another placement.

Implement two_knights(n).

Input

n: The largest board size to consider.

Output

Return n counts in order, for board sizes 1 through n.

제약 조건

1 ≤ n ≤ 10,000. Counts fit signed 64-bit integers.

예시

예시 1
입력:
n = 3

예상 출력:
expected = [0, 6, 28]
입력:
long long n = 3;

예상 출력:
std::vector<long long> expected = {0, 6, 28};
입력:
long n = 3;

예상 출력:
long[] expected = new long[] {0, 6, 28};

설명

A 1 × 1 board cannot hold two knights. A 2 × 2 board has six pairs and no attacks. A 3 × 3 board has 36 pairs, of which eight attack, leaving 28.

예시 2
입력:
n = 1

예상 출력:
expected = [0]
입력:
long long n = 1;

예상 출력:
std::vector<long long> expected = {0};
입력:
long n = 1;

예상 출력:
long[] expected = new long[] {0};

설명

Two distinct squares are required, but the board has only one.

참고 자료

이 문제는 CodeUtility에 맞게 수정되었습니다. 위의 설명과 제한 조건을 따르세요.

다른 사람의 풀이 보기

커뮤니티 솔루션

아직 공개된 풀이가 없습니다. 문제를 풀고 첫 풀이를 공유하세요.