# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
242542 | VEGAnn | Prosjecni (COCI16_prosjecni) | C++14 | 6 ms | 640 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 <bits/stdc++.h>
#define all(x) x.begin(),x.end()
using namespace std;
const int N = 510;
int n, m, k, id[N], x, a[N][N];
string s[N], t;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef _LOCAL
freopen("in.txt","r",stdin);
#endif // _LOCAL
cin >> n;
if (n & 1){
for (int i = 1; i <= n * n; i++){
cout << i;
if (i % n == 0)
cout << '\n';
else cout << " ";
}
} else {
if (n == 2)
cout << -1;
else {
int sum = 0;
for (int i = 0; i < n / 2; i++) {
a[0][i] = i + 1;
sum += a[0][i];
}
for (int i = n / 2; i < n - 1; i++) {
a[0][i] = i + 2;
sum += a[0][i];
}
a[0][n - 1] = a[0][n / 2] * n - sum;
sum = a[0][n - 1];
for (int i = 1; i < n / 2; i++){
for (int j = 0; j < n; j++)
a[i][j] = a[i - 1][j] + sum;
}
for (int j = 0; j < n; j++)
a[n / 2][j] = a[n / 2 - 1][j] + sum * 2;
for (int i = n / 2 + 1; i < n - 1; i++){
for (int j = 0; j < n; j++)
a[i][j] = a[i - 1][j] + sum;
}
for (int j = 0; j < n; j++)
a[n - 1][j] = a[n - 2][j] + sum * (a[0][n - 1] - a[0][n - 2]);
for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++)
cout << a[i][j] << " ";
cout << '\n';
}
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |