#include <bits/stdc++.h>
#define ll long long
#define s second
#define f first
#define pb push_back
#define left (h*2),l,(l + r)/2
#define right (h*2+1),(l+r)/2 + 1,r
#define pii pair <int,int>
using namespace std;
const int N = 503;
char a[N][N];
vector <pii> neighbours = {{0,1}, {0,-1}, {1,0}, {-1,0}};
int n,m;
bitset <501> dp[N][5003];
bitset <501> mask[N];
bool valid(int x,int y){
return (x >= 1 && x <= n && y >= 1 && y <= m && a[x][y] == '.');
}
signed main(){
ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
int k;
cin>>n>>m>>k;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++){
cin >> a[i][j];
if (a[i][j] == '.') dp[i][0][j] = 1,mask[i][j] = 1;
else mask[i][j] = 0;
}
string s;
cin>>s;
map <char,pii> mp;
mp['N'] = {-1,0};
mp['S'] = {1,0};
mp['E'] = {0,+1};
mp['W'] = {0,-1};
s='%' + s;
for (int i = 1; i <= k; i++){
for (int x = 1; x <= n; x++){
bitset <501> nw;
if (s[i] == 'E' || s[i] == '?'){
nw |= (dp[x][i - 1] << 1) & mask[x];
}
if (s[i] == 'W' || s[i] == '?'){
nw |= (dp[x][i - 1] >> 1) & mask[x];
}
if (s[i] == 'N' || s[i] == '?'){
nw |= dp[x + 1][i - 1] & mask[x];
}
if (s[i] == 'S' || s[i] == '?'){
nw |= dp[x - 1][i - 1] & mask[x];
}
dp[x][i] = nw;
}
}
int ans=0;
for (int i = 1; i <= n; i++)
ans += dp[i][k].count();
cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
33116 KB |
Output is correct |
2 |
Correct |
5 ms |
33116 KB |
Output is correct |
3 |
Correct |
5 ms |
33116 KB |
Output is correct |
4 |
Correct |
7 ms |
33112 KB |
Output is correct |
5 |
Correct |
5 ms |
33332 KB |
Output is correct |
6 |
Correct |
4 ms |
33116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
33116 KB |
Output is correct |
2 |
Correct |
5 ms |
33116 KB |
Output is correct |
3 |
Correct |
5 ms |
33116 KB |
Output is correct |
4 |
Correct |
7 ms |
33112 KB |
Output is correct |
5 |
Correct |
5 ms |
33332 KB |
Output is correct |
6 |
Correct |
4 ms |
33116 KB |
Output is correct |
7 |
Correct |
5 ms |
33116 KB |
Output is correct |
8 |
Correct |
4 ms |
33116 KB |
Output is correct |
9 |
Correct |
5 ms |
33344 KB |
Output is correct |
10 |
Correct |
5 ms |
33364 KB |
Output is correct |
11 |
Correct |
2 ms |
5468 KB |
Output is correct |
12 |
Correct |
8 ms |
33116 KB |
Output is correct |
13 |
Correct |
4 ms |
33116 KB |
Output is correct |
14 |
Correct |
5 ms |
33116 KB |
Output is correct |
15 |
Correct |
4 ms |
33116 KB |
Output is correct |
16 |
Correct |
2 ms |
5468 KB |
Output is correct |
17 |
Correct |
5 ms |
33116 KB |
Output is correct |
18 |
Correct |
4 ms |
33256 KB |
Output is correct |
19 |
Correct |
5 ms |
33116 KB |
Output is correct |
20 |
Correct |
6 ms |
33252 KB |
Output is correct |
21 |
Correct |
2 ms |
5468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
33116 KB |
Output is correct |
2 |
Correct |
5 ms |
33116 KB |
Output is correct |
3 |
Correct |
5 ms |
33116 KB |
Output is correct |
4 |
Correct |
7 ms |
33112 KB |
Output is correct |
5 |
Correct |
5 ms |
33332 KB |
Output is correct |
6 |
Correct |
4 ms |
33116 KB |
Output is correct |
7 |
Correct |
5 ms |
33116 KB |
Output is correct |
8 |
Correct |
4 ms |
33116 KB |
Output is correct |
9 |
Correct |
5 ms |
33344 KB |
Output is correct |
10 |
Correct |
5 ms |
33364 KB |
Output is correct |
11 |
Correct |
2 ms |
5468 KB |
Output is correct |
12 |
Correct |
8 ms |
33116 KB |
Output is correct |
13 |
Correct |
4 ms |
33116 KB |
Output is correct |
14 |
Correct |
5 ms |
33116 KB |
Output is correct |
15 |
Correct |
4 ms |
33116 KB |
Output is correct |
16 |
Correct |
2 ms |
5468 KB |
Output is correct |
17 |
Correct |
5 ms |
33116 KB |
Output is correct |
18 |
Correct |
4 ms |
33256 KB |
Output is correct |
19 |
Correct |
5 ms |
33116 KB |
Output is correct |
20 |
Correct |
6 ms |
33252 KB |
Output is correct |
21 |
Correct |
2 ms |
5468 KB |
Output is correct |
22 |
Correct |
154 ms |
157552 KB |
Output is correct |
23 |
Correct |
137 ms |
157776 KB |
Output is correct |
24 |
Correct |
141 ms |
157604 KB |
Output is correct |
25 |
Correct |
134 ms |
157800 KB |
Output is correct |
26 |
Correct |
135 ms |
157520 KB |
Output is correct |
27 |
Correct |
187 ms |
157772 KB |
Output is correct |
28 |
Correct |
164 ms |
157780 KB |
Output is correct |
29 |
Correct |
164 ms |
157780 KB |
Output is correct |
30 |
Correct |
168 ms |
157760 KB |
Output is correct |
31 |
Correct |
171 ms |
157524 KB |
Output is correct |
32 |
Correct |
180 ms |
157564 KB |
Output is correct |
33 |
Correct |
191 ms |
157744 KB |
Output is correct |
34 |
Correct |
184 ms |
157748 KB |
Output is correct |
35 |
Correct |
181 ms |
157780 KB |
Output is correct |
36 |
Correct |
204 ms |
157568 KB |
Output is correct |