#include <bits/stdc++.h>
using namespace std;
#define all(a) a.begin(),a.end()
#define pb push_back
#define vt vector
#define endl '\n'
typedef long long ll;
const ll mod=1e9+7;
const ll inf=mod;
const int N=5e6+4;
int n,m,k;
char c[600][600];
int dp[600][600][600];
void solve(){
cin>>n>>m>>k;
for(int i=1; i<=n; ++i){
for(int j=1; j<=m; ++j){
cin>>c[i][j];
if(c[i][j]!='#') dp[0][i][j]=1;
}
}
string s;
cin>>s;
s='#'+s;
for(int x=1; x<=k; ++x){
for(int i=1; i<=n; ++i){
for(int j=1; j<=m; ++j){
if(c[i][j]=='#') continue;
if((s[x]=='N' || s[x]=='?') && dp[x-1][i+1][j]) dp[x][i][j]=1;
if((s[x]=='S' || s[x]=='?') && dp[x-1][i-1][j]) dp[x][i][j]=1;
if((s[x]=='E' || s[x]=='?') && dp[x-1][i][j-1]) dp[x][i][j]=1;
if((s[x]=='W' || s[x]=='?') && dp[x-1][i][j+1]) dp[x][i][j]=1;
}
}
}
int ans=0;
for(int i=1; i<=n; ++i) for(int j=1; j<=m; ++j){
ans+=dp[k][i][j];
}
cout<<ans<<endl;
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int tt=1;
// cin>>tt;
while(tt--) {
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
144220 KB |
Output is correct |
2 |
Correct |
18 ms |
144120 KB |
Output is correct |
3 |
Correct |
20 ms |
144220 KB |
Output is correct |
4 |
Correct |
19 ms |
144188 KB |
Output is correct |
5 |
Correct |
17 ms |
144220 KB |
Output is correct |
6 |
Correct |
17 ms |
144220 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
144220 KB |
Output is correct |
2 |
Correct |
18 ms |
144120 KB |
Output is correct |
3 |
Correct |
20 ms |
144220 KB |
Output is correct |
4 |
Correct |
19 ms |
144188 KB |
Output is correct |
5 |
Correct |
17 ms |
144220 KB |
Output is correct |
6 |
Correct |
17 ms |
144220 KB |
Output is correct |
7 |
Correct |
18 ms |
144204 KB |
Output is correct |
8 |
Correct |
21 ms |
144212 KB |
Output is correct |
9 |
Correct |
23 ms |
144220 KB |
Output is correct |
10 |
Correct |
17 ms |
144220 KB |
Output is correct |
11 |
Correct |
15 ms |
143964 KB |
Output is correct |
12 |
Correct |
18 ms |
144220 KB |
Output is correct |
13 |
Correct |
21 ms |
144212 KB |
Output is correct |
14 |
Correct |
24 ms |
144216 KB |
Output is correct |
15 |
Correct |
17 ms |
144216 KB |
Output is correct |
16 |
Correct |
15 ms |
143964 KB |
Output is correct |
17 |
Correct |
18 ms |
144220 KB |
Output is correct |
18 |
Correct |
21 ms |
144244 KB |
Output is correct |
19 |
Correct |
23 ms |
144216 KB |
Output is correct |
20 |
Correct |
17 ms |
144216 KB |
Output is correct |
21 |
Correct |
16 ms |
143964 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
144220 KB |
Output is correct |
2 |
Correct |
18 ms |
144120 KB |
Output is correct |
3 |
Correct |
20 ms |
144220 KB |
Output is correct |
4 |
Correct |
19 ms |
144188 KB |
Output is correct |
5 |
Correct |
17 ms |
144220 KB |
Output is correct |
6 |
Correct |
17 ms |
144220 KB |
Output is correct |
7 |
Correct |
18 ms |
144204 KB |
Output is correct |
8 |
Correct |
21 ms |
144212 KB |
Output is correct |
9 |
Correct |
23 ms |
144220 KB |
Output is correct |
10 |
Correct |
17 ms |
144220 KB |
Output is correct |
11 |
Correct |
15 ms |
143964 KB |
Output is correct |
12 |
Correct |
18 ms |
144220 KB |
Output is correct |
13 |
Correct |
21 ms |
144212 KB |
Output is correct |
14 |
Correct |
24 ms |
144216 KB |
Output is correct |
15 |
Correct |
17 ms |
144216 KB |
Output is correct |
16 |
Correct |
15 ms |
143964 KB |
Output is correct |
17 |
Correct |
18 ms |
144220 KB |
Output is correct |
18 |
Correct |
21 ms |
144244 KB |
Output is correct |
19 |
Correct |
23 ms |
144216 KB |
Output is correct |
20 |
Correct |
17 ms |
144216 KB |
Output is correct |
21 |
Correct |
16 ms |
143964 KB |
Output is correct |
22 |
Runtime error |
164 ms |
262144 KB |
Execution killed with signal 9 |
23 |
Halted |
0 ms |
0 KB |
- |