#include <iostream>
#include <vector>
#include <algorithm>
#define int int64_t
using namespace std;
signed main()
{
int r, c, m;
cin >> r >> c >> m;
vector<vector<bool>> tab;
vector<vector<bool>> st(r, vector<bool>(c));
vector<vector<bool>> old(r, vector<bool>(c));
for (int i = 0; i < r; i++)
{
for (int j = 0; j < c; j++)
{
char ch;
cin >> ch;
st[i][j] = (ch == '.');
}
}
tab = st;
string seq;
cin >> seq;
// reverse(seq.begin(), seq.end());
for (int i = 0; i < m; i++)
{
if (seq[i] == 'N') seq[i] = 'S';
else if (seq[i] == 'S') seq[i] = 'N';
else if (seq[i] == 'E') seq[i] = 'W';
else if (seq[i] == 'W') seq[i] = 'E';
}
for (int t = 0; t < m; t++)
{
swap(old, tab);
for (int i = 0; i < r; i++)
{
for (int j = 0; j < c; j++)
{
tab[i][j] = false;
if (seq[t] == 'N' || seq[t] == '?') tab[i][j] = tab[i][j] || ((i - 1 >= 0) ? old[i - 1][j] : false);
if (seq[t] == 'W' || seq[t] == '?') tab[i][j] = tab[i][j] || ((j - 1 >= 0) ? old[i][j - 1] : false);
if (seq[t] == 'S' || seq[t] == '?') tab[i][j] = tab[i][j] || ((i + 1 < r) ? old[i + 1][j] : false);
if (seq[t] == 'E' || seq[t] == '?') tab[i][j] = tab[i][j] || ((j + 1 < c) ? old[i][j + 1] : false);
tab[i][j] = tab[i][j] && st[i][j];
}
}
/*
for (auto v : tab)
{
for (auto j : v)
{
cout << j << " ";
}
cout << "\n";
}
cout << "\n";
*/
}
int res = 0;
for (auto v : tab) for (auto j : v) res += j;
cout << res << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
376 KB |
Output is correct |
2 |
Correct |
11 ms |
376 KB |
Output is correct |
3 |
Correct |
12 ms |
376 KB |
Output is correct |
4 |
Correct |
12 ms |
376 KB |
Output is correct |
5 |
Correct |
11 ms |
376 KB |
Output is correct |
6 |
Correct |
11 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
376 KB |
Output is correct |
2 |
Correct |
11 ms |
376 KB |
Output is correct |
3 |
Correct |
12 ms |
376 KB |
Output is correct |
4 |
Correct |
12 ms |
376 KB |
Output is correct |
5 |
Correct |
11 ms |
376 KB |
Output is correct |
6 |
Correct |
11 ms |
376 KB |
Output is correct |
7 |
Correct |
12 ms |
248 KB |
Output is correct |
8 |
Correct |
15 ms |
376 KB |
Output is correct |
9 |
Correct |
13 ms |
376 KB |
Output is correct |
10 |
Correct |
13 ms |
376 KB |
Output is correct |
11 |
Correct |
14 ms |
376 KB |
Output is correct |
12 |
Correct |
13 ms |
376 KB |
Output is correct |
13 |
Correct |
17 ms |
376 KB |
Output is correct |
14 |
Correct |
22 ms |
376 KB |
Output is correct |
15 |
Correct |
14 ms |
376 KB |
Output is correct |
16 |
Correct |
13 ms |
376 KB |
Output is correct |
17 |
Correct |
13 ms |
376 KB |
Output is correct |
18 |
Correct |
18 ms |
380 KB |
Output is correct |
19 |
Correct |
22 ms |
376 KB |
Output is correct |
20 |
Correct |
21 ms |
504 KB |
Output is correct |
21 |
Correct |
14 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
376 KB |
Output is correct |
2 |
Correct |
11 ms |
376 KB |
Output is correct |
3 |
Correct |
12 ms |
376 KB |
Output is correct |
4 |
Correct |
12 ms |
376 KB |
Output is correct |
5 |
Correct |
11 ms |
376 KB |
Output is correct |
6 |
Correct |
11 ms |
376 KB |
Output is correct |
7 |
Correct |
12 ms |
248 KB |
Output is correct |
8 |
Correct |
15 ms |
376 KB |
Output is correct |
9 |
Correct |
13 ms |
376 KB |
Output is correct |
10 |
Correct |
13 ms |
376 KB |
Output is correct |
11 |
Correct |
14 ms |
376 KB |
Output is correct |
12 |
Correct |
13 ms |
376 KB |
Output is correct |
13 |
Correct |
17 ms |
376 KB |
Output is correct |
14 |
Correct |
22 ms |
376 KB |
Output is correct |
15 |
Correct |
14 ms |
376 KB |
Output is correct |
16 |
Correct |
13 ms |
376 KB |
Output is correct |
17 |
Correct |
13 ms |
376 KB |
Output is correct |
18 |
Correct |
18 ms |
380 KB |
Output is correct |
19 |
Correct |
22 ms |
376 KB |
Output is correct |
20 |
Correct |
21 ms |
504 KB |
Output is correct |
21 |
Correct |
14 ms |
376 KB |
Output is correct |
22 |
Execution timed out |
1089 ms |
760 KB |
Time limit exceeded |
23 |
Halted |
0 ms |
0 KB |
- |