-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path14500.cpp
114 lines (109 loc) · 4.11 KB
/
14500.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
void a(int y, int x);
void b(int y, int x);
void c(int y, int x);
void d(int y, int x);
void e(int y, int x);
vector<int>v;
int n, m;
int graph[501][501] = {0, };
int main (){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//입력
cin >> n >> m;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
cin >> graph[i][j];
}
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
a(i, j);
b(i, j);
c(i, j);
d(i, j);
e(i, j);
}
}
cout << *max_element(v.begin(), v.end());
}
void a(int y, int x){
if(y+3 <= n)
v.push_back(graph[y][x]+graph[y+1][x]+graph[y+2][x]+graph[y+3][x]);
if(x+3 <= m)
v.push_back(graph[y][x]+graph[y][x+1]+graph[y][x+2]+graph[y][x+3]);
if(y-3 >= 1)
v.push_back(graph[y][x]+graph[y-1][x]+graph[y-2][x]+graph[y-3][x]);
if(x-3 >= 1)
v.push_back(graph[y][x]+graph[y][x-1]+graph[y][x-2]+graph[y][x-3]);
return;
}
void b(int y, int x){
if(y+1 <= m && x+1 <= n)
v.push_back(graph[y][x]+graph[y+1][x]+graph[y][x+1]+graph[y+1][x+1]);
if(y-1 >= 1 && x+1 <= n)
v.push_back(graph[y][x]+graph[y-1][x]+graph[y][x+1]+graph[y-1][x+1]);
if(y+1 <= m && x-1 >= 1)
v.push_back(graph[y][x]+graph[y+1][x]+graph[y][x-1]+graph[y+1][x-1]);
if(y-1 >= 1 && x-1 >= 1)
v.push_back(graph[y][x]+graph[y-1][x]+graph[y][x-1]+graph[y-1][x-1]);
}
void c(int y, int x){
if(y+2 <= n && x+1<= m)
v.push_back(graph[y][x]+graph[y+1][x]+graph[y+2][x]+graph[y+2][x+1]);
if(y+2 <= n && x-1 >= 1)
v.push_back(graph[y][x]+graph[y+1][x]+graph[y+2][x]+graph[y+2][x-1]);
if(y+1 <= n && x-2 >= 1)
v.push_back(graph[y][x]+graph[y][x-1]+graph[y][x-2]+graph[y+1][x-2]);
if(y-1 >= 1 && x-2 >= 1)
v.push_back(graph[y][x]+graph[y][x-1]+graph[y][x-2]+graph[y-1][x-2]);
if(y-2 >= 1 && x+1 <= m)
v.push_back(graph[y][x]+graph[y-1][x]+graph[y-2][x]+graph[y-2][x+1]);
if(y-2 >= 1 && x-1 >= 1)
v.push_back(graph[y][x]+graph[y-1][x]+graph[y-2][x]+graph[y-2][x-1]);
if(y+1 <= n && x+2 <= m)
v.push_back(graph[y][x]+graph[y][x+1]+graph[y][x+2]+graph[y+1][x+2]);
if(y-1 >= 1 && x+2 <= m)
v.push_back(graph[y][x]+graph[y][x+1]+graph[y][x+2]+graph[y-1][x+2]);
}
void d(int y, int x){
if(y+2<=n && x+1 <=m)
v.push_back(graph[y][x]+graph[y+1][x]+graph[y+1][x+1]+graph[y+2][x+1]);
if(y+2<=n && x-1 >= 1)
v.push_back(graph[y][x]+graph[y+1][x]+graph[y+1][x-1]+graph[y+2][x-1]);
if(y+1 <= n && x-2 >= 1)
v.push_back(graph[y][x]+graph[y][x-1]+graph[y+1][x-1]+graph[y+1][x-2]);
if(y-1 >= 1 && x-2 >= 1)
v.push_back(graph[y][x]+graph[y][x-1]+graph[y-1][x-1]+graph[y-1][x-2]);
if(y-2 >=1 && x-1 >=1)
v.push_back(graph[y][x]+graph[y-1][x]+graph[y-1][x-1]+graph[y-2][x-1]);
if(y-2 >=1 && x+1 <= m)
v.push_back(graph[y][x]+graph[y-1][x]+graph[y-1][x+1]+graph[y-2][x+1]);
if(y+1 <= n && x+2 <= m)
v.push_back(graph[y][x]+graph[y][x+1]+graph[y+1][x+1]+graph[y+1][x+2]);
if(y-1 >= 1 && x+2 <= m)
v.push_back(graph[y][x]+graph[y][x+1]+graph[y-1][x+1]+graph[y-1][x+2]);
}
void e(int y, int x){
if(x+2 <= m && y+1 <= n)
v.push_back(graph[y][x]+graph[y][x+1]+graph[y][x+2]+graph[y+1][x+1]);
if(y-1 >= 1 && x+2 <= m)
v.push_back(graph[y][x]+graph[y][x+1]+graph[y][x+2]+graph[y-1][x+1]);
if(y+2 <= n && x+1 <= m)
v.push_back(graph[y][x]+graph[y+1][x]+graph[y+1][x+1]+graph[y+2][x]);
if(y+2 <= n && x-1 >= 1)
v.push_back(graph[y][x]+graph[y+1][x]+graph[y+1][x-1]+graph[y+2][x]);
if(y+1 <= n && x-2 >= 1)
v.push_back(graph[y][x]+graph[y][x-1]+graph[y][x-2]+graph[y+1][x-1]);
if(y-1 >= 1 && x-2 >= 1)
v.push_back(graph[y][x]+graph[y][x-1]+graph[y-1][x-1]+graph[y][x-2]);
if(y-2 >= 1 && x+1 <=m)
v.push_back(graph[y][x]+graph[y-1][x]+graph[y-1][x+1]+graph[y-2][x]);
if(y-2 >=1 && x-1 >= 1)
v.push_back(graph[y][x]+graph[y-1][x]+graph[y-1][x-1]+graph[y-2][x]);
}