Submission #301843

# Submission time Handle Problem Language Result Execution time Memory
301843 2020-09-18T08:48:48 Z colazcy Prosjecni (COCI16_prosjecni) C++17
24 / 120
2 ms 384 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 - 1];
	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

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