Submission #32274

# Submission time Handle Problem Language Result Execution time Memory
32274 2017-10-06T05:07:49 Z cscandkswon Prosjecni (COCI16_prosjecni) C++14
120 / 120
0 ms 1152 KB
#include <cstdio>

int N, A[101][101], K;

int main() {
	int i, j, s;
	scanf("%d", &N);
	if (N == 1) {
		puts("1");
		return 0;
	}
	else if (N == 2) {
		puts("-1");
		return 0;
	}
	K = N*(N - 1) / 2;
	for (i = 0; i < N-1; i++) {
		for (j = 0; j < N - 1; j++) A[i][j] = K*i + j + 1;
		A[i][N - 1] = K*(i + 1);
	}
	for (i = 0; i < N; i++) {
		for (j = 0, s = 0; j < N - 1; j++) s += A[j][i];
		A[N - 1][i] = A[N - 2][i] * N - s;
	}
	for (i = 0; i < N; i++) {
		for (j = 0; j < N; j++) printf("%d ", A[i][j]);
		puts("");
	}
	return 0;
}

Compilation message

prosjecni.cpp: In function 'int main()':
prosjecni.cpp:7:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
                 ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 1152 KB Output is correct
2 Correct 0 ms 1152 KB Output is correct
3 Correct 0 ms 1152 KB Output is correct
4 Correct 0 ms 1152 KB Output is correct
5 Correct 0 ms 1152 KB Output is correct
6 Correct 0 ms 1152 KB Output is correct
7 Correct 0 ms 1152 KB Output is correct
8 Correct 0 ms 1152 KB Output is correct
9 Correct 0 ms 1152 KB Output is correct
10 Correct 0 ms 1152 KB Output is correct