//In The Name of Allah
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair < int , int > pii;
typedef pair < ll , ll > pll;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x.size())
const int N = 500 + 10;
const int M = 5000 + 10;
const ll mod = 1e9 + 7;
const ll inf = 1e18 + 10;
bitset < N > dp[2][N], row[N];
int main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, m, len; char c;
cin >> n >> m >> len;
for (int i = 1; i <= n; i ++)
for (int j = 1; j <= m; j ++)
cin >> c, dp[0][i][j] = row[i][j] = (c == '.');
string s;
cin >> s;
s = '.' + s;
for (int t = 1; t <= len; t ++){
for (int i = 1; i <= n; i ++){
if (s[t] == 'N')
dp[t & 1][i] = dp[(t & 1) ^ 1][i + 1] & row[i];
if (s[t] == 'S')
dp[t & 1][i] = dp[(t & 1) ^ 1][i - 1] & row[i];
if (s[t] == 'W')
dp[t & 1][i] = (dp[(t & 1) ^ 1][i] >> 1) & row[i];
if (s[t] == 'E')
dp[t & 1][i] = (dp[(t & 1) ^ 1][i] << 1) & row[i];
if (s[t] == '?')
dp[t & 1][i] = (dp[(t & 1) ^ 1][i + 1] | dp[(t & 1) ^ 1][i - 1] | (dp[(t & 1) ^ 1][i] << 1) | (dp[(t & 1) ^ 1][i] >> 1)) & row[i];
}
}
int ans = 0;
for (int i = 1; i <= n; i ++)
ans += dp[len & 1][i].count();
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
2 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
2 ms |
364 KB |
Output is correct |
18 |
Correct |
2 ms |
364 KB |
Output is correct |
19 |
Correct |
2 ms |
364 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
21 |
Correct |
2 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
2 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
2 ms |
364 KB |
Output is correct |
18 |
Correct |
2 ms |
364 KB |
Output is correct |
19 |
Correct |
2 ms |
364 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
21 |
Correct |
2 ms |
364 KB |
Output is correct |
22 |
Correct |
105 ms |
760 KB |
Output is correct |
23 |
Correct |
105 ms |
760 KB |
Output is correct |
24 |
Correct |
107 ms |
748 KB |
Output is correct |
25 |
Correct |
101 ms |
748 KB |
Output is correct |
26 |
Correct |
99 ms |
748 KB |
Output is correct |
27 |
Correct |
173 ms |
748 KB |
Output is correct |
28 |
Correct |
182 ms |
748 KB |
Output is correct |
29 |
Correct |
190 ms |
748 KB |
Output is correct |
30 |
Correct |
177 ms |
748 KB |
Output is correct |
31 |
Correct |
175 ms |
876 KB |
Output is correct |
32 |
Correct |
233 ms |
896 KB |
Output is correct |
33 |
Correct |
232 ms |
748 KB |
Output is correct |
34 |
Correct |
236 ms |
760 KB |
Output is correct |
35 |
Correct |
237 ms |
748 KB |
Output is correct |
36 |
Correct |
228 ms |
748 KB |
Output is correct |