-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay4.cpp
More file actions
91 lines (84 loc) · 2.22 KB
/
Day4.cpp
File metadata and controls
91 lines (84 loc) · 2.22 KB
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
#include <bits/stdc++.h>
#define int long long
#define allr(x) (x).rbegin(), (x).rend()
#define all(x) (x).begin(), (x).end()
#define ld long double
#define INF (int)(1e18)
#define MOD 1000000007
using namespace std;
int dx[] = {0, 0, 1, -1, -1, 1, 1, -1};
int dy[] = {1, -1, 0, 0, -1, 1, -1, 1};
void Part1() {
vector<string> v;
string s;
while (cin >> s && s != "?") {
v.push_back(s);
}
int n = v.size(), m = v[0].size();
auto in = [&](int i, int j) {
return i >= 0 && j >= 0 && i < n && j < m;
};
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (v[i][j] == '@') {
int cnt = 0;
for (int k = 0; k < 8; k++) {
int ni = i + dx[k], nj = j + dy[k];
if (in(ni, nj) && v[ni][nj] == '@') {
v[ni][nj] = 'x';
cnt++;
}
}
if (cnt <= 3)ans++;
}
}
}
cout << ans << "\n";
}
void Part2() {
vector<string> v;
string s;
while (cin >> s && s != "?") {
v.push_back(s);
}
int n = v.size(), m = v[0].size();
auto in = [&](int i, int j) {
return i >= 0 && j >= 0 && i < n && j < m;
};
int ans = 0, sz = n * m;
while (sz--) {
bool f = false;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (v[i][j] == '@') {
int cnt = 0;
for (int k = 0; k < 8; k++) {
int ni = i + dx[k], nj = j + dy[k];
if (in(ni, nj) && v[ni][nj] == '@') {
cnt++;
}
}
if (cnt <= 3) {
v[i][j] = '.';
ans++;
}
}
}
}
}
cout << ans << "\n";
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("promote.in","r",stdin);
// freopen("promote.out","w",stdout);
int tests = 1;
// cin >> tests;
while (tests--) {
//Part1();
Part2();
}
}