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;
int ans;
bitset < 503 > dp[ 5003 ][ 503 ];
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 ++){
// if(!dp[ 0 ][ i ][ j ]){
// dp[ k ][ i ] = 0;
// continue;
// }
if(s[ k - 1 ] == 'N'/* && i + 1 <= n*/)
dp[ k ][ i ] |= dp[ k - 1 ][ i + 1 ] & dp[ 0 ][ i ];
else if(s[ k - 1 ] == 'S'/* && i - 1 > 0*/)
dp[ k ][ i ] |= dp[ k - 1 ][ i - 1 ] & dp[ 0 ][ i ];
else if(s[ k - 1 ] == 'W'/* && j + 1 <= m*/)
dp[ k ][ i ] |= (dp[ k - 1 ][ i ] >> 1) & dp[ 0 ][ i ];
else if(s[ k - 1 ] == 'E'/* && j - 1 > 0*/)
dp[ k ][ i ] |= (dp[ k - 1 ][ i ] << 1) & dp[ 0 ][ i ];
else if(s[ k - 1 ] == '?'){
dp[ k ][ i ] |= dp[ k - 1 ][ i + 1 ] & dp[ 0 ][ i ];
dp[ k ][ i ] |= dp[ k - 1 ][ i - 1 ] & dp[ 0 ][ i ];
dp[ k ][ i ] |= (dp[ k - 1 ][ i ] >> 1) & dp[ 0 ][ i ];
dp[ k ][ i ] |= (dp[ k - 1 ][ i ] << 1) & dp[ 0 ][ i ];
}
}
}
// 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
#..
.#.
..#
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |