Submission #147025

# Submission time Handle Problem Language Result Execution time Memory
147025 2019-08-27T07:16:48 Z lovro_nidogon1 Prosjecni (COCI16_prosjecni) C++14
120 / 120
3 ms 380 KB
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n, x, y, z, by;
	cin >> n;
	if(n == 2) {
		cout << -1;
		return 0;
	}
	if(n%2 == 0) {
		x = 0;
		by = 0;
		for(int i = 0; i < n; i++) {
			y = 0;

			if(i == n - 2) {
				z = x + 1;
			}
			if(i == n - 1) {
				x = (z * n) - by - 1;
			}		
			by = by + x + 1;
			for(int j = 0; j < n - 1; j++) {
				x++;		
				y = y + x;	
				cout << x << " ";												
			}
			cout << (x * n) - y << '\n';
			x = (x * n) - y;
		}
	} else {
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				x++;
				cout << x << " ";
			}
			cout << endl;
		}
	}
}

Compilation message

prosjecni.cpp: In function 'int main()':
prosjecni.cpp:4:9: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
  int n, x, y, z, by;
         ^
prosjecni.cpp:20:12: warning: 'z' may be used uninitialized in this function [-Wmaybe-uninitialized]
     x = (z * n) - by - 1;
         ~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 380 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct