#include<bits/stdc++.h>
using namespace std;
#define ll long long
int R, C, M;
vector<string> mp;
string S;
int dirs[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
int dp[101][101][102];
bool vis[101][101][101];
int ans = 0;
void solve(){
cin>>R>>C>>M;
mp.assign(R, "");
for(string &s:mp) cin>>s;
cin>>S;
for(int i = 0; i < R; i++){
for(int j = 0; j < C; j++){
for(int k = 0; k <= M; k++) dp[i][j][k] = 0;
}
}
for(int k = 0; k <= M; k++){
for(int i = 0; i < R; i++){
for(int j = 0; j < C; j++){
if(mp[i][j] == '#') continue;
if(k == 0){
if(S[k] == 'W')
dp[i][j][k] = j-1 >= 0 && mp[i][j-1] != '#';
if(S[k] == 'E')
dp[i][j][k] = j+1 < C && mp[i][j+1] != '#';
if(S[k] == 'S')
dp[i][j][k] = i+1 < R && mp[i+1][j] != '#';
if(S[k] == 'N')
dp[i][j][k] = i-1 >= 0 && mp[i-1][j] != '#';
if(S[k] == '?'){
for(int d = 0; d < 4; d++){
int ni = i+dirs[d][0];
int nj = j+dirs[d][1];
if(ni < 0 || ni >= R || nj < 0 || nj >= C || mp[ni][nj] == '#') continue;
dp[i][j][k] |= 1;
}
}
continue;
}
if(S[k-1] == 'W')
dp[i][j][k] = j+1 < C && mp[i][j+1] != '#' && dp[i][j+1][k-1];
if(S[k-1] == 'E')
dp[i][j][k] = j-1 >= 0 && mp[i][j-1] != '#' && dp[i][j-1][k-1];
if(S[k-1] == 'S')
dp[i][j][k] = i-1 >= 0 && mp[i-1][j] != '#' && dp[i-1][j][k-1];
if(S[k-1] == 'N')
dp[i][j][k] = i+1 < R && mp[i+1][j] != '#' && dp[i+1][j][k-1];
if(S[k-1] == '?'){
for(int d = 0; d < 4; d++){
int ni = i+dirs[d][0];
int nj = j+dirs[d][1];
if(ni < 0 || ni >= R || nj < 0 || nj >= C || mp[ni][nj] == '#') continue;
dp[i][j][k] |= dp[ni][nj][k-1];
}
}
}
}
}
for(int i = 0; i < R; i++){
for(int j = 0; j < C; j++){
if(dp[i][j][M] == 1){
ans++;
}
}
}
cout<<ans<<endl;
}
int main(){
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
4392 KB |
Output is correct |
2 |
Correct |
7 ms |
4284 KB |
Output is correct |
3 |
Correct |
9 ms |
4308 KB |
Output is correct |
4 |
Correct |
8 ms |
4308 KB |
Output is correct |
5 |
Correct |
6 ms |
4368 KB |
Output is correct |
6 |
Correct |
4 ms |
4308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
4392 KB |
Output is correct |
2 |
Correct |
7 ms |
4284 KB |
Output is correct |
3 |
Correct |
9 ms |
4308 KB |
Output is correct |
4 |
Correct |
8 ms |
4308 KB |
Output is correct |
5 |
Correct |
6 ms |
4368 KB |
Output is correct |
6 |
Correct |
4 ms |
4308 KB |
Output is correct |
7 |
Correct |
9 ms |
4364 KB |
Output is correct |
8 |
Correct |
12 ms |
4308 KB |
Output is correct |
9 |
Correct |
11 ms |
4364 KB |
Output is correct |
10 |
Correct |
6 ms |
4308 KB |
Output is correct |
11 |
Correct |
3 ms |
4308 KB |
Output is correct |
12 |
Correct |
15 ms |
4308 KB |
Output is correct |
13 |
Correct |
16 ms |
4368 KB |
Output is correct |
14 |
Correct |
18 ms |
4348 KB |
Output is correct |
15 |
Correct |
8 ms |
4284 KB |
Output is correct |
16 |
Correct |
3 ms |
4308 KB |
Output is correct |
17 |
Correct |
17 ms |
4308 KB |
Output is correct |
18 |
Correct |
19 ms |
4308 KB |
Output is correct |
19 |
Correct |
15 ms |
4308 KB |
Output is correct |
20 |
Correct |
8 ms |
4368 KB |
Output is correct |
21 |
Correct |
3 ms |
4308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
4392 KB |
Output is correct |
2 |
Correct |
7 ms |
4284 KB |
Output is correct |
3 |
Correct |
9 ms |
4308 KB |
Output is correct |
4 |
Correct |
8 ms |
4308 KB |
Output is correct |
5 |
Correct |
6 ms |
4368 KB |
Output is correct |
6 |
Correct |
4 ms |
4308 KB |
Output is correct |
7 |
Correct |
9 ms |
4364 KB |
Output is correct |
8 |
Correct |
12 ms |
4308 KB |
Output is correct |
9 |
Correct |
11 ms |
4364 KB |
Output is correct |
10 |
Correct |
6 ms |
4308 KB |
Output is correct |
11 |
Correct |
3 ms |
4308 KB |
Output is correct |
12 |
Correct |
15 ms |
4308 KB |
Output is correct |
13 |
Correct |
16 ms |
4368 KB |
Output is correct |
14 |
Correct |
18 ms |
4348 KB |
Output is correct |
15 |
Correct |
8 ms |
4284 KB |
Output is correct |
16 |
Correct |
3 ms |
4308 KB |
Output is correct |
17 |
Correct |
17 ms |
4308 KB |
Output is correct |
18 |
Correct |
19 ms |
4308 KB |
Output is correct |
19 |
Correct |
15 ms |
4308 KB |
Output is correct |
20 |
Correct |
8 ms |
4368 KB |
Output is correct |
21 |
Correct |
3 ms |
4308 KB |
Output is correct |
22 |
Runtime error |
39 ms |
9888 KB |
Execution killed with signal 11 |
23 |
Halted |
0 ms |
0 KB |
- |