#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cstring>
using namespace std;
int main() {
int n;
cin >>n;
int brr;
int br = 1;
int mat[110][110];
if (n == 2) {
cout <<-1;
return 0;
}
if (n%2 == 0) {
for (int i=0; i<n-1; i++) {
brr = 0;
for (int j=0; j<n; j++) {
if (j == n-1) {
br = (br-1) * n - brr;
}
mat[i][j] = br;
//cout <<br <<" ";
brr+=br;
br++;
}
//cout <<"\n";
}
int br = 0;
for (int i=0; i<n; i++) {
brr = 0;
for (int j=0; j<n-1; j++) {
brr+=mat[j][i];
br = mat[j][i];
}
br = br * n - brr;
mat[n-1][i] = br;
}
}
else {
for (int i=0; i<n; i++) {
for (int j=0; j<n; j++) {
cout <<br <<" ";
br++;
}
cout <<"\n";
}
return 0;
}
for (int i=0; i<n; i++) {
for (int j=0; j<n; j++) {
cout <<mat[i][j] <<" ";
}
cout <<"\n";
}
return 0;
}
# |
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 |
256 KB |
Output is correct |
4 |
Correct |
9 ms |
256 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 |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
504 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |