-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path15739.cpp
67 lines (65 loc) · 1.06 KB
/
15739.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <stdio.h>
int main(void) {
int A[100][100] = {};
int B[10000] = {};
int N;
scanf("%d", &N);
for(int i = 0; i<N; i++){
for(int j = 0; j<N; j++){
scanf("%d", &A[i][j]);
if(A[i][j] <= 0){
printf("FALSE");
return 0;
}
else if(A[i][j] > N*N){
printf("FALSE");
return 0;
}
}
}
for(int i = 0; i<N; i++){
for(int j = 0; j<N; j++){
B[A[i][j]] = 1;
}
}
for(int i = 1; i<N*N+1; i++){
if(B[i] >= 2){
printf("FALSE");
return 0;
}
if(B[i] == 0){
printf("FALSE");
return 0;
}
}
int S1 = 0;
int S3 = 0;
for(int i = 0; i<N; i++){
int S = 0;
int S2 = 0;
S1 += A[i][i];
S3 += A[i][N-i-1];
for(int j = 0; j < N; j++){
S += A[i][j];
S2 += A[j][i];
}
if(S != (N*(N*N+1))/2){
printf("FALSE");
return 0;
}
if(S2 != (N*(N*N+1))/2){
printf("FALSE");
return 0;
}
}
if(S3 != (N*(N*N+1))/2){
printf("FALSE");
return 0;
}
if(S1 != (N*(N*N+1))/2){
printf("FALSE");
return 0;
}
printf("TRUE");
return 0;
}