# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
301852 | 2020-09-18T08:51:48 Z | colazcy | Prosjecni (COCI16_prosjecni) | C++17 | 2 ms | 512 KB |
#include <cstdio> using namespace std; const int maxn = 128; int val[maxn][maxn],n; int main(){ scanf("%d",&n); if(n % 2 == 1){ int tot = 0; for(int i = 1;i <= n;i++){ for(int j = 1;j <= n;j++)printf("%d ",++tot); printf("\n"); } return 0; } if(n == 2)return puts("-1"),0; for(int i = 1;i < n;i++)val[1][i] = i; int sum = 0; for(int i = 1;i < n;i++)sum += val[1][i]; val[1][n] = val[1][n - 1] * n - sum; for(int i = 2;i < n;i++) for(int j = 1;j <= n;j++) val[i][j] = val[i - 1][j] + val[1][n]; for(int i = 1;i <= n;i++){ int sum = 0; for(int j = 1;j < n;j++)sum += val[j][i]; val[n][i] = val[n - 1][i] * n - sum; } for(int i = 1;i <= n;i++){ for(int j = 1;j <= n;j++)printf("%d ",val[i][j]); printf("\n"); } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 256 KB | Output is correct |
2 | Correct | 0 ms | 256 KB | Output is correct |
3 | Correct | 0 ms | 288 KB | Output is correct |
4 | Correct | 0 ms | 256 KB | Output is correct |
5 | Correct | 1 ms | 256 KB | Output is correct |
6 | Correct | 1 ms | 288 KB | Output is correct |
7 | Correct | 1 ms | 512 KB | Output is correct |
8 | Correct | 2 ms | 384 KB | Output is correct |
9 | Correct | 2 ms | 384 KB | Output is correct |
10 | Correct | 2 ms | 384 KB | Output is correct |