# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
146747 | fran_1024 | Prosjecni (COCI16_prosjecni) | C++14 | 4 ms | 380 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |