Matrices and Sums

시간 제한1초메모리 제한2048 MB

요약
원소가 -1, 0, 1인 n x n 행렬을 만들어 n개의 행 합과 n개의 열 합이 모두 다르게 하거나, 불가능하면 불가능하다고 답한다.
난이도

보통10점 중 5점

유형
수학, 그리디, 구현
정답자
아직 제출이 없습니다

문제

Given a positive integer nn, you should construct an n×nn \times n integer matrix MM satisfying the following conditions:

  • For all elements M_i,jM\_{i,j} (1≤i,j≤n1 \le i, j \le n), the absolute value ∣M_i,j∣≤1|M\_{i,j}| \le 1.
  • The row and column sums R_1,R_2,…,R_n,C_1,C_2,…,C_nR\_1, R\_2, \ldots, R\_n, C\_1, C\_2, \ldots, C\_n are pairwise distinct, where R_x=∑_i=1nM_x,iR\_x = \sum\_{i = 1}^{n} M\_{x,i} and C_x=∑_i=1nM_i,xC\_x = \sum\_{i = 1}^{n} M\_{i,x}.

There may exist multiple solutions or no solution.

입력

The first line contains a single integer nn (1≤n≤10001 \le n \le 1000).

출력

The first line must contain one string "Yes" (without quotes) if a solution exists, or "No" (without quotes) if there is no solution.

When a solution exists, print nn more lines, each containing nn integers, denoting the matrix MM you construct.

If multiple solutions exist, print any one of them.

힌트

  • In the first example, R_1=1R\_1 = 1, R_2=0R\_2 = 0, C_1=2C\_1 = 2, and C_2=−1C\_2 = -1 are all distinct.
  • In the second example, R_1=C_1R\_1 = C\_1 always holds, so no solution exists.

예제2

  1. 예제 1

    입력
    2
    
    예상 출력
    Yes
    1 0
    1 -1
    
  2. 예제 2

    입력
    1
    
    예상 출력
    No