This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
ll dp[ 103 ][ 103 ][ 103 ], ans;
// bitset < 100111 > bst[ n ];
string s;
int main (){
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 += dp[ t ][ i ][ j ];
// cout << dp[ k ][ i ][ j ] << " ";
}
// cout << endl;
}
// cout << endl;
// }
cout << ans;
}
/*
5 9 7
...##....
..#.##..#
..#....##
.##...#..
....#....
WS?EE??
3 3 3
#..
.#.
..#
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |