#include <bits/stdc++.h>
#define PB push_back
#define ST first
#define ND second
#define _ ios_base::sync_with_stdio(0); cin.tie(0);
//mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
using namespace std;
using ll = long long;
using pi = pair<int,int>;
using vi = vector<int>;
const int nax = 502;
int r,c,m;
string s;
bitset<nax>dp[nax], mp[nax], tmp[nax];
int main() {_
cin >> r >> c >> m;
for(int i = 1; i <= r; ++i) {
for(int j = 1; j <= c; ++j) {
char t;
cin >> t;
if(t == '.') {
dp[i].set(j);
mp[i].set(j);
}
}
}
cin >> s;
for(int i = 0; i < m; ++i) {
if(s[i] == 'N') {
for(int j = 1; j <= r; ++j) {
dp[j] = (dp[j+1] & mp[j]);
}
} else if(s[i] == 'S') {
for(int j = r; j >= 1; --j) {
dp[j] = (dp[j-1] & mp[j]);
}
} else if(s[i] == 'W') {
for(int j = 1; j <= r; ++j) {
dp[j] = ((dp[j] >> 1) & mp[j]);
}
} else if(s[i] == 'E') {
for(int j = 1; j <= r; ++j) {
dp[j] = ((dp[j] << 1) & mp[j]);
}
} else {
for(int j = 1; j <= r; ++j) {
tmp[j] = (((dp[j] << 1) | (dp[j] >> 1) | (dp[j+1]) | (dp[j-1])) & mp[j]);
}
for(int j = 1; j <= r; ++j) {
dp[j] = tmp[j];
}
}
}
int ans = 0;
for(int i = 1; i <= r; ++i) {
ans += dp[i].count();
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
6 ms |
256 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
6 ms |
512 KB |
Output is correct |
18 |
Correct |
6 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
6 ms |
384 KB |
Output is correct |
21 |
Correct |
6 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
6 ms |
256 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
6 ms |
512 KB |
Output is correct |
18 |
Correct |
6 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
6 ms |
384 KB |
Output is correct |
21 |
Correct |
6 ms |
384 KB |
Output is correct |
22 |
Correct |
95 ms |
640 KB |
Output is correct |
23 |
Correct |
99 ms |
632 KB |
Output is correct |
24 |
Correct |
96 ms |
760 KB |
Output is correct |
25 |
Correct |
96 ms |
740 KB |
Output is correct |
26 |
Correct |
94 ms |
640 KB |
Output is correct |
27 |
Correct |
153 ms |
640 KB |
Output is correct |
28 |
Correct |
157 ms |
888 KB |
Output is correct |
29 |
Correct |
158 ms |
640 KB |
Output is correct |
30 |
Correct |
155 ms |
640 KB |
Output is correct |
31 |
Correct |
157 ms |
720 KB |
Output is correct |
32 |
Correct |
197 ms |
768 KB |
Output is correct |
33 |
Correct |
202 ms |
760 KB |
Output is correct |
34 |
Correct |
200 ms |
768 KB |
Output is correct |
35 |
Correct |
207 ms |
760 KB |
Output is correct |
36 |
Correct |
199 ms |
640 KB |
Output is correct |