#include <bits/stdc++.h>
using namespace std;
int dp(int w){
if(w==1) return 1;
return w+dp(w-1);
}
int n;
int main(){
//huh
cin>>n;
if(n==2) cout<<"-1";
else if(n%2){
for(int i=0;i<n;i++){
for(int j=0;j<n;j++)
cout<<i*n+j+1<<" ";
cout<<endl;
}
}
else{
int g=dp(n-1);
int sum=0;
int d[n],d2[n];
for(int i=0;i<n-1;i++){d[i]=i+1;}
d[n-1]=g;
for(int i=0;i<n-1;i++){d2[i]=1+g*i;sum+=d2[i];}
int bottomleft=d2[n-2]*n-sum;
int diff=g-n+1;
for(int i=0;i<n-1;i++){
for(int j=0;j<n;j++){
cout<<d[j]<<" ";
d[j]+=g;
}
cout<<endl;
}
for(int i=0;i<n-1;i++){
cout<<bottomleft+i<<" ";
}
cout<<bottomleft+n-2+diff;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
380 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
300 KB |
Output is correct |
8 |
Correct |
6 ms |
376 KB |
Output is correct |
9 |
Correct |
6 ms |
376 KB |
Output is correct |
10 |
Correct |
6 ms |
376 KB |
Output is correct |