-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathday8.cpp
78 lines (70 loc) · 1.36 KB
/
day8.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
#include <bits/stdc++.h>
#define endl '\n'
#define eat cin
#define moo cout
#define int long long
using namespace std;
int N, M;
vector<string> S;
int ans = 0;
bool vis[1000][1000];
void aux(int x, int y, int dx, int dy){
int mx = -1;
for(; x >= 0 && y >= 0 && x < N && y < M; x += dx, y += dy){
if(S[x][y] - '0' > mx) vis[x][y] = 1;
mx = max(mx, (int)S[x][y] - '0');
}
}
void part1(){
for(int i = 0; i < N; i++){
aux(i, 0, 0, 1);
aux(i, M-1, 0, -1);
}
for(int i = 0; i < M; i++){
aux(0, i, 1, 0);
aux(N-1, i, -1, 0);
}
for(int i = 0; i < N; i++){
for(int j = 0; j < M; j++){
if(vis[i][j]) ans++;
//moo << vis[i][j] << ' ';
}
//moo << endl;
}
}
int aux2(int x, int y, int dx, int dy){
int z = S[x][y] - '0';
x += dx, y += dy;
int res = 0;
for(; x >= 0 && y >= 0 && x < N && y < M; x += dx, y += dy){
res++;
if(S[x][y] - '0' >= z) break;
}
return res;
}
int ans2 = 0;
void part2(){
for(int i = 0; i < N; i++){
for(int j = 0; j < M; j++){
int r = aux2(i, j, 1, 0) * aux2(i, j, -1, 0);
r *= aux2(i, j, 0, 1) * aux2(i, j, 0, -1);
ans2 = max(ans2, r);
}
}
}
int32_t main(){
eat.tie(0) -> sync_with_stdio(0);
string Cur;
while(getline(eat, Cur)){
if(Cur.size() == 0) break;
S.push_back(Cur);
}
N = S.size();
M = S[0].size();
part1();
part2();
moo << ans << endl;
moo << ans2 << endl;
// solve();
//moo << sum << endl;
}