Submission #146783

#TimeUsernameProblemLanguageResultExecution timeMemory
146783fabjanmProsjecni (COCI16_prosjecni)C++98
120 / 120
4 ms504 KiB
#include<iostream> #include<vector> #include<algorithm> #include<string> using namespace std; int mat[105][105]; int niz[105]; int main(){ int n; cin>>n; if(n==1){ cout<<1; return 0; } if(n % 2 == 1){ int br=2*n; int poc=n*10; for(int i=0;i<n;i++){ mat[i][n/2+1]=poc; poc+=br*2; } for(int i=0;i<n;i++){ int poc=mat[i][n/2+1]; for(int j=0;j<n;j++){ mat[i][j]=poc-2*(n/2-j); } } for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ cout<<mat[i][j]<<" "; } cout<<endl; } } else{ if(n==2){ cout<<-1; return 0; } for(int i=0;i<n-1;i++)niz[i]=i+1; int br=n*(n-1)/2; niz[n-1]=br; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ mat[i][j]=br*niz[i]+niz[j]; } } for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ cout<<mat[i][j]<<" "; } cout<<endl; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...