#include <bits/stdc++.h>
#define int long long
#define ff first
#define ss second
using namespace std;
void solve()
{
int r, c, m;
cin >> r >> c >> m;
vector<vector<bool>> grid(r, vector<bool>(c));
for (int i = 0; i < r; i++)
for (int j = 0; j < c; j++)
{
char c;
cin >> c;
if (c == '.')
grid[i][j] = 0;
else
grid[i][j] = 1;
}
vector<char> does(m);
for (int i = 0; i < m; i++)
cin >> does[i];
vector<bitset<500>> prev(r);
// i hate bitstes
vector<bitset<500>> after(r);
for (int i = 0; i < r; i++)
for (int j = 0; j < c; j++)
after[i][j] = !grid[i][j];
// ja sam mirza bušatlić
// aprapraprpa
vector<bitset<500>> next(r);
for (int i = 0; i < r; i++)
for (int j = 0; j < c; j++)
prev[i][j] = !grid[i][j];
for (int cur = 0; cur < m; cur++)
{
for (int i = 0; i < r; i++)
{
if (does[cur] == 'W')
{
next[i]|=(prev[i]>>1);
}
else if (does[cur] == 'S')
{
if (i+1 < r)
next[i+1]|=prev[i];
}
else if (does[cur] == 'E')
{
next[i]|=(prev[i]<<1);
}
else if (does[cur] == 'N')
{
if (i-1 >= 0)
next[i-1]|=prev[i];
}
else
{
next[i]|=(prev[i]<<1);
if (i+1 < r)
next[i+1]|=prev[i];
next[i]|=(prev[i]>>1);
if (i-1 >= 0)
next[i-1]|=prev[i];
}
}
for (int i = 0; i < r; i++)
{
next[i] &= after[i];
prev[i] = next[i];
next[i].reset();
}
}
int ans = 0;
for (int i = 0; i < r; i++)
ans+=prev[i].count();
cout << ans << '\n';
return;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
464 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
464 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
464 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
392 KB |
Output is correct |
21 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
464 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
464 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
392 KB |
Output is correct |
21 |
Correct |
1 ms |
460 KB |
Output is correct |
22 |
Correct |
83 ms |
604 KB |
Output is correct |
23 |
Correct |
86 ms |
844 KB |
Output is correct |
24 |
Correct |
83 ms |
860 KB |
Output is correct |
25 |
Correct |
83 ms |
844 KB |
Output is correct |
26 |
Correct |
81 ms |
604 KB |
Output is correct |
27 |
Correct |
116 ms |
840 KB |
Output is correct |
28 |
Correct |
115 ms |
604 KB |
Output is correct |
29 |
Correct |
116 ms |
604 KB |
Output is correct |
30 |
Correct |
116 ms |
844 KB |
Output is correct |
31 |
Correct |
113 ms |
840 KB |
Output is correct |
32 |
Correct |
143 ms |
860 KB |
Output is correct |
33 |
Correct |
140 ms |
840 KB |
Output is correct |
34 |
Correct |
140 ms |
848 KB |
Output is correct |
35 |
Correct |
142 ms |
860 KB |
Output is correct |
36 |
Correct |
138 ms |
860 KB |
Output is correct |