답안 #209136

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
209136 2020-03-13T09:10:01 Z DysonSphere Prosjecni (COCI16_prosjecni) C++14
120 / 120
6 ms 376 KB
#include<bits/stdc++.h>
using namespace std;
int arr[105][105];
int main(){
	// freopen("in.txt","r",stdin);
	// freopen("out.txt","w",stdout);
	int n;
	cin>>n;
	if(n==1){
		cout<<1;
		return 0;
	}
	if(n==2){
		cout<<-1;
		return 0;
	}
	if(n%2==1){
		for(int i=0;i<n;i++){
			for(int j=1;j<=n;j++){
				cout<<(i*n)+j<<" ";
			}
			cout<<endl;
		}
		return 0;
	}

	for(int i=0;i<n-1;i++){
		arr[0][i]=i+1;
	}
	arr[0][n-1]=0;
	for(int i=0;i<n-1;i++){
		arr[0][n-1]+=arr[0][i];
	}

	for(int i=1;i<n-1;i++){
		arr[i][0]=arr[i-1][n-1]+1;
		for(int j=1;j<n-1;j++){
			arr[i][j]=arr[i][j-1]+1;
		}
		arr[i][n-1]=arr[0][n-1]*(i+1);
	}

	for(int i=0;i<n;i++){
		int sum=0;
		for(int j=0;j<n-1;j++){
			sum+=arr[j][i];
		}
		int las=arr[n-2][i];
		arr[n-1][i]=((las*n)-sum);
	}

	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			cout<<arr[i][j]<<" ";
		}
		cout<<endl;
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 248 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 256 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 376 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