Submission #146747

# Submission time Handle Problem Language Result Execution time Memory
146747 2019-08-25T21:06:33 Z fran_1024 Prosjecni (COCI16_prosjecni) C++14
120 / 120
4 ms 380 KB
#include <iostream>
#include <vector>
using namespace std;

int main() {
	int n;
	cin >> n;
	int x = n * n;
	if(x == 4) {
		cout << -1;
		return 0;
	}
	int m = 0;
	if(n & 1) for(int i = 0; i < x; i++) {
		cout << i + 1 << ' ';
		if((i + 1) % n == 0) {
			cout << '\n';
		}
	} else {
		vector <int> ar(n);
		for(int i = 0; i < n; i++) {
			ar[i] = i + 1;
		}
		int x = ar[n / 2] * n - (n * (n - 1) / 2);
		ar[n - 1] = x;
		
		int fsum = 0;
		int nkd;
		
		for(int i = 0; i < n; i++) {
			if(i == n - 1) {
				int y = nkd * n - fsum;
				for(int j = 0; j < n; j++) {
					ar[j] = y + j;
					if(j == n - 1) {
						ar[j] += x - j - 1;
					}
				}
			}
			fsum += ar[0];
			
			if(i == n / 2) nkd = ar[0];
			for(int j = 0; j < n; j++) {
				cout << ar[j] << ' ';
				ar[j] += x;
			}
			cout << '\n';
		}
	}
	return 0;
}

Compilation message

prosjecni.cpp: In function 'int main()':
prosjecni.cpp:13:6: warning: unused variable 'm' [-Wunused-variable]
  int m = 0;
      ^
prosjecni.cpp:32:17: warning: 'nkd' may be used uninitialized in this function [-Wmaybe-uninitialized]
     int y = nkd * n - fsum;
             ~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 380 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 4 ms 376 KB Output is correct