-
Notifications
You must be signed in to change notification settings - Fork 0
/
21a.cpp
55 lines (46 loc) · 1.36 KB
/
21a.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
// c++ -std=c++20 -O2 21a.cpp && ./a.out
#include <iostream>
#include <ranges>
#include <string>
#include <vector>
using namespace std;
using std::ranges::iota_view;
const int DX[] = {1, 0, -1, 0};
const int DY[] = {0, 1, 0, -1};
int solve(vector<string> a) {
int n = a.size();
auto f = vector<vector<bool>>(n, vector<bool>(n));
auto ff = vector<vector<bool>>(n, vector<bool>(n));
for (int i : iota_view { 0, n })
for (int j : iota_view { 0, n })
f[i][j] = a[i][j] == 'S';
for (int it : iota_view { 0, 64 }) {
for (int i : iota_view { 0, n }) {
for (int j : iota_view { 0, n }) {
if (a[i][j] == '#') continue;
ff[i][j] = false;
for (int d : iota_view { 0, 4 }) {
int x = i + DX[d];
int y = j + DY[d];
if (0 <= x && x < n && 0 <= y && y < n && f[x][y]) {
ff[i][j] = true;
break;
}
}
}
}
f = ff;
}
int result = 0;
for (int i : iota_view { 0, n })
for (int j : iota_view { 0, n })
if (f[i][j]) result++;
return result;
}
int main() {
vector<string> lines;
string line;
while (cin >> line) lines.push_back(line);
cout << solve(lines) << endl;
return 0;
}