-
Notifications
You must be signed in to change notification settings - Fork 0
/
711B.cpp
94 lines (80 loc) · 1.66 KB
/
711B.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
using namespace std;
const int maxn=1000;
const int inf=1e9+10;
int n;
int map[maxn][maxn];
int main(){
cin>>n;
//horizontal
int maxnn=-10000;
int minu=inf;
//vertical
int maxnn_ver=-10000;
int minu_ver=inf;
//diagonal
int maxnn_dia=-10000;
int minu_dia=inf;
int sum_dia=0;
//horiz
for(int i=0;i<n;i++){
int sum=0;
for(int j=0;j<n;j++){
cin>>map[i][j];
sum+=map[i][j];
if(i==j){
sum_dia+=map[i][j];
}
}
maxnn=max(sum,maxnn);
minu=min(sum,minu);
}
//vertical
for(int i=0;i<n;i++){
int sum=0;
for(int j=0;j<n;j++){
sum+=map[j][i];
}
maxnn_ver=max(sum,maxnn_ver);
minu_ver=min(sum,minu_ver);
}
//dia array
int sum_anti_dia=0;
for(int i=0;i<n;i++){
sum_anti_dia+=map[i][n-1-i];
}
maxnn_dia=max(sum_anti_dia,sum_dia);
minu_dia=min(sum_anti_dia,sum_dia);
int dia_diff=maxnn_dia-minu_dia;
int hori_diff=maxnn-minu;
int ver_diff=maxnn_ver-minu_ver;
cout<<dia_diff<<" "<<hori_diff<<" "<<ver_diff<<"\n";
if(dia_diff==0&&hori_diff==0&&ver_diff==0){
cout<<"-1";
return 0;
}
else if(dia_diff==0&&hori_diff==ver_diff&&hori_diff>0){
cout<<hori_diff;
return 0;
} if(hori_diff==0&&dia_diff==ver_diff&&dia_diff>0){
cout<<dia_diff;
return 0;
} if(ver_diff==0&&dia_diff==hori_diff&&hori_diff>0){
cout<<hori_diff;
return 0;
}if(ver_diff==dia_diff&&dia_diff==hori_diff&&hori_diff>0){
cout<<hori_diff;
return 0;
}
else{
cout<<"-1";
return 0;
}
}