Submission #209112

# Submission time Handle Problem Language Result Execution time Memory
209112 2020-03-13T08:35:05 Z MertD014 Prosjecni (COCI16_prosjecni) C++17
0 / 120
1000 ms 376 KB
#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(){
	freopen("all.in","r",stdin);
	freopen("all.out","w",stdout);
	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=(n-1)*(n-1)-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;
}

Compilation message

prosjecni.cpp: In function 'int main()':
prosjecni.cpp:13:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
  freopen("all.in","r",stdin);
  ~~~~~~~^~~~~~~~~~~~~~~~~~~~
prosjecni.cpp:14:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
  freopen("all.out","w",stdout);
  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 1090 ms 256 KB Time limit exceeded
2 Execution timed out 1088 ms 256 KB Time limit exceeded
3 Execution timed out 1083 ms 376 KB Time limit exceeded
4 Execution timed out 1093 ms 256 KB Time limit exceeded
5 Execution timed out 1091 ms 256 KB Time limit exceeded
6 Execution timed out 1089 ms 256 KB Time limit exceeded
7 Execution timed out 1086 ms 256 KB Time limit exceeded
8 Execution timed out 1086 ms 256 KB Time limit exceeded
9 Execution timed out 1090 ms 256 KB Time limit exceeded
10 Execution timed out 1097 ms 256 KB Time limit exceeded