#include <iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <sstream>
#include <cstring>
#include <bitset>
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse,-fgcse-lm")
#pragma GCC optimize("-ftree-pre,-ftree-vrp")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
#define ll long long int
#define pb push_back
#define pll pair < ll , ll >
#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
ll inf2 = 3e18;
bool dp[ 502 ][ 502 ][ 502 ];
int ans;
// bitset < 100111 > bst[ n ];
string s;
int main (){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
ll n, m, t;
char c;
cin >> n >> m >> t;
for(int i = 1; i <= n; i ++){
for(int j = 1; j <= m; j ++){
cin >> c;
if(c == '.')
dp[ 0 ][ i ][ j ] = 1;
}
}
cin >> s;
// s = '#' + s;
// reverse(all(s));
for(int k = 1; k <= t; k ++){
for(int i = 1; i <= n; i ++){
for(int j = 1; j <= m; j ++){
if(!dp[ 0 ][ i ][ j ]){
dp[ k ][ i ][ j ] = 0;
continue;
}
if(s[ k - 1 ] == 'N' && i + 1 <= n)
dp[ k ][ i ][ j ] |= dp[ k - 1 ][ i + 1 ][ j ];
else if(s[ k - 1 ] == 'S' && i - 1 > 0)
dp[ k ][ i ][ j ] |= dp[ k - 1 ][ i - 1 ][ j ];
else if(s[ k - 1 ] == 'W' && j + 1 <= m)
dp[ k ][ i ][ j ] |= dp[ k - 1 ][ i ][ j + 1 ];
else if(s[ k - 1 ] == 'E' && j - 1 > 0)
dp[ k ][ i ][ j ] |= dp[ k - 1 ][ i ][ j - 1 ];
else if(s[ k - 1 ] == '?'){
if(i + 1 <= n)
dp[ k ][ i ][ j ] |= dp[ k - 1 ][ i + 1 ][ j ];
if(i - 1 > 0)
dp[ k ][ i ][ j ] |= dp[ k - 1 ][ i - 1 ][ j ];
if(j + 1 <= m)
dp[ k ][ i ][ j ] |= dp[ k - 1 ][ i ][ j + 1 ];
if(j - 1 > 0)
dp[ k ][ i ][ j ] |= dp[ k - 1 ][ i ][ j - 1 ];
}
}
}
}
// for(int k = 0; k <= t; k ++){
for(int i = 1; i <= n; i ++){
for(int j = 1; j <= m; j ++){
ans += ((int)dp[ t ][ i ][ j ]);
// cout << dp[ k ][ i ][ j ] << " ";
}
// cout << endl;
}
// cout << endl;
// }
cout << ans;
}
/*
5 9 7
...##....
..#.##..#
..#....##
.##...#..
....#....
WS?EE??
3 3 3
#..
.#.
..#
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
5580 KB |
Output is correct |
2 |
Correct |
6 ms |
5580 KB |
Output is correct |
3 |
Correct |
7 ms |
5580 KB |
Output is correct |
4 |
Correct |
7 ms |
5580 KB |
Output is correct |
5 |
Correct |
6 ms |
5580 KB |
Output is correct |
6 |
Correct |
4 ms |
5580 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
5580 KB |
Output is correct |
2 |
Correct |
6 ms |
5580 KB |
Output is correct |
3 |
Correct |
7 ms |
5580 KB |
Output is correct |
4 |
Correct |
7 ms |
5580 KB |
Output is correct |
5 |
Correct |
6 ms |
5580 KB |
Output is correct |
6 |
Correct |
4 ms |
5580 KB |
Output is correct |
7 |
Correct |
5 ms |
5580 KB |
Output is correct |
8 |
Correct |
7 ms |
5580 KB |
Output is correct |
9 |
Correct |
8 ms |
5608 KB |
Output is correct |
10 |
Correct |
6 ms |
5580 KB |
Output is correct |
11 |
Correct |
4 ms |
5580 KB |
Output is correct |
12 |
Correct |
5 ms |
5580 KB |
Output is correct |
13 |
Correct |
6 ms |
5580 KB |
Output is correct |
14 |
Correct |
8 ms |
5672 KB |
Output is correct |
15 |
Correct |
6 ms |
5580 KB |
Output is correct |
16 |
Correct |
5 ms |
5580 KB |
Output is correct |
17 |
Correct |
10 ms |
5580 KB |
Output is correct |
18 |
Correct |
6 ms |
5580 KB |
Output is correct |
19 |
Correct |
7 ms |
5580 KB |
Output is correct |
20 |
Correct |
5 ms |
5580 KB |
Output is correct |
21 |
Correct |
4 ms |
5580 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
5580 KB |
Output is correct |
2 |
Correct |
6 ms |
5580 KB |
Output is correct |
3 |
Correct |
7 ms |
5580 KB |
Output is correct |
4 |
Correct |
7 ms |
5580 KB |
Output is correct |
5 |
Correct |
6 ms |
5580 KB |
Output is correct |
6 |
Correct |
4 ms |
5580 KB |
Output is correct |
7 |
Correct |
5 ms |
5580 KB |
Output is correct |
8 |
Correct |
7 ms |
5580 KB |
Output is correct |
9 |
Correct |
8 ms |
5608 KB |
Output is correct |
10 |
Correct |
6 ms |
5580 KB |
Output is correct |
11 |
Correct |
4 ms |
5580 KB |
Output is correct |
12 |
Correct |
5 ms |
5580 KB |
Output is correct |
13 |
Correct |
6 ms |
5580 KB |
Output is correct |
14 |
Correct |
8 ms |
5672 KB |
Output is correct |
15 |
Correct |
6 ms |
5580 KB |
Output is correct |
16 |
Correct |
5 ms |
5580 KB |
Output is correct |
17 |
Correct |
10 ms |
5580 KB |
Output is correct |
18 |
Correct |
6 ms |
5580 KB |
Output is correct |
19 |
Correct |
7 ms |
5580 KB |
Output is correct |
20 |
Correct |
5 ms |
5580 KB |
Output is correct |
21 |
Correct |
4 ms |
5580 KB |
Output is correct |
22 |
Runtime error |
479 ms |
251448 KB |
Execution killed with signal 11 |
23 |
Halted |
0 ms |
0 KB |
- |