# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
147129 | badrovinho | Prosjecni (COCI16_prosjecni) | C++14 | 4 ms | 452 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>
using namespace std;
int mat[105][105];
int main (){
int n;
cin >> n;
if (n % 2 == 1){
int x = 1;
for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++){
cout << x << " ";
x++;
}
cout << "\n";
}
}else {
if (n == 2){
cout << -1;
}else {
//GLAVNO
for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++){
mat[i][j] = 0;
}
}
int k = 1;
int suma = 0;
for (int i = 0; i < n-1; i++){
mat[0][i] = k;
suma += k;
k++;
}
int pr = mat[0][n/2];
int x = (n*pr)-suma;
mat[0][n-1] = x;
for (int i = 1; i < n-1; i++){
mat[i][0] = mat[i-1][n-1] + 1;
int suma = mat[i][0];
for (int j = 1; j < n-1; j++){
mat[i][j] = mat[i][j-1] + 1;
suma += mat[i][j];
}
int pr = mat[i][n/2];
int x = (n*pr)-suma;
mat[i][n-1] = x;
}
for (int j = 0; j < n; j++){
int suma = 0;
for (int i = 0; i < n-1; i++){
suma += mat[i][j];
}
int pr = mat[n/2][j];
int x = (n*pr)-suma;
mat[n-1][j] = x;
}
for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++){
cout << mat[i][j] << " ";
}
cout << endl;
}
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |