Submission #146783

# Submission time Handle Problem Language Result Execution time Memory
146783 2019-08-26T06:33:45 Z fabjanm Prosjecni (COCI16_prosjecni) C++
120 / 120
4 ms 504 KB
#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 time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 252 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 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 4 ms 504 KB Output is correct
10 Correct 3 ms 376 KB Output is correct