답안 #94156

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
94156 2019-01-16T11:59:04 Z ekrem Prosjecni (COCI16_prosjecni) C++
120 / 120
3 ms 376 KB
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define N 105
using namespace std;

int n, a[N][N];

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	scanf("%d",&n);
	if(n == 2){
		puts("-1");
		return 0;
	}
	if(n % 2){
		for(int i = 1; i <= n; i++,puts(""))
			for(int j = 1; j <= n; j++)
				printf("%d ", (i - 1)*n + j);
		return 0;
	}
	for(int j = 1; j <= n; j++){
		if(j == n/2)
			a[1][j] = a[1][j - 1] + 3;
		else if(j == n/2 + 3)
			a[1][j] = a[1][j - 1] + 2;
		else
			a[1][j] = a[1][j - 1] + 1;
	}
	int ek = a[1][n];
	for(int i = 2; i <= n; i++)
		for(int j = 1; j <= n; j++){
			if(i == n/2)
				a[i][j] = a[i - 1][j] + 3*ek;
			else if(i == n/2 + 3)
				a[i][j] = a[i - 1][j] + 2*ek;
			else
				a[i][j] = a[i - 1][j] + ek;
		}
	for(int i = 1; i <= n; i++,puts(""))
			for(int j = 1; j <= n; j++)
				printf("%d ", a[i][j]);
	// for(int i = 1; i <= n; i++){
	// 	int top = 0;
	// 	for(int j = 1; j <= n; j++)
	// 		top += a[i][j];
	// 	top /= n;
	// 	int f = 0;
	// 	for(int j = 1; j <= n; j++)
	// 		if(top == a[i][j])
	// 			f = 1;
	// 	if(!f){
	// 		cout << i << "AMK" << endl;
	// 	}
	// }
	return 0;
}

Compilation message

prosjecni.cpp: In function 'int main()':
prosjecni.cpp:14:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct