//*
#pragma GCC optimize("O2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2,sse,sse2,fma,tune=native")
//*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int ,int > pii;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll maxn = 2000;
const ll mod =1e9+7;
const ld PI = acos((ld)-1);
#define pb push_back
#define endl '\n'
#define dokme(x) cout << x , exit(0)
#define migmig ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ms(x , y) memset(x , y , sizeof x)
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}
int n , m , t;
string s[maxn];
string p;
bitset < maxn > block[maxn] , dp[2][maxn];
int32_t main(){
migmig;
cin >> n >> m >> t;
for(int i = 0 ; i < n ; i ++)
cin >> s[i];
cin >> p;
for(int i = 1 ; i <= n ; i ++)
for(int j = 1; j <= m ; j ++)
if(s[i - 1][j - 1] == '.')block[i][j] = dp[0][i][j] = 1;
for(int j = 0 ; j < t ; j ++){
char cur = p[j];
for(int i = 1 ; i <= n ; i ++){
if(cur == 'S')
dp[1-(j%2)][i] = dp[j%2][i-1]&block[i];
if(cur == 'N')
dp[1-(j%2)][i] = dp[j%2][i+1]&block[i];
if(cur == 'W')
dp[1-(j%2)][i] = (dp[j%2][i] >> 1)&block[i];
if(cur == 'E')
dp[1-(j%2)][i] = (dp[j%2][i] << 1)&block[i];
if(cur == '?')
dp[1-(j%2)][i] = ((dp[j%2][i] << 1) | (dp[j%2][i] >> 1) | dp[j%2][i+1] | dp[j%2][i-1])&block[i];
}
}
ll ans = 0;
for(int i = 1 ; i <= n ; i ++)
ans += dp[t%2][i].count();
cout << ans;
return(0);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
492 KB |
Output is correct |
10 |
Correct |
2 ms |
492 KB |
Output is correct |
11 |
Correct |
2 ms |
492 KB |
Output is correct |
12 |
Correct |
2 ms |
620 KB |
Output is correct |
13 |
Correct |
2 ms |
492 KB |
Output is correct |
14 |
Correct |
2 ms |
492 KB |
Output is correct |
15 |
Correct |
2 ms |
492 KB |
Output is correct |
16 |
Correct |
2 ms |
492 KB |
Output is correct |
17 |
Correct |
2 ms |
492 KB |
Output is correct |
18 |
Correct |
2 ms |
492 KB |
Output is correct |
19 |
Correct |
2 ms |
492 KB |
Output is correct |
20 |
Correct |
2 ms |
492 KB |
Output is correct |
21 |
Correct |
2 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
492 KB |
Output is correct |
10 |
Correct |
2 ms |
492 KB |
Output is correct |
11 |
Correct |
2 ms |
492 KB |
Output is correct |
12 |
Correct |
2 ms |
620 KB |
Output is correct |
13 |
Correct |
2 ms |
492 KB |
Output is correct |
14 |
Correct |
2 ms |
492 KB |
Output is correct |
15 |
Correct |
2 ms |
492 KB |
Output is correct |
16 |
Correct |
2 ms |
492 KB |
Output is correct |
17 |
Correct |
2 ms |
492 KB |
Output is correct |
18 |
Correct |
2 ms |
492 KB |
Output is correct |
19 |
Correct |
2 ms |
492 KB |
Output is correct |
20 |
Correct |
2 ms |
492 KB |
Output is correct |
21 |
Correct |
2 ms |
492 KB |
Output is correct |
22 |
Correct |
170 ms |
1024 KB |
Output is correct |
23 |
Correct |
166 ms |
1264 KB |
Output is correct |
24 |
Correct |
158 ms |
1388 KB |
Output is correct |
25 |
Correct |
156 ms |
1388 KB |
Output is correct |
26 |
Correct |
155 ms |
1388 KB |
Output is correct |
27 |
Correct |
229 ms |
1388 KB |
Output is correct |
28 |
Correct |
245 ms |
1388 KB |
Output is correct |
29 |
Correct |
231 ms |
1388 KB |
Output is correct |
30 |
Correct |
230 ms |
1260 KB |
Output is correct |
31 |
Correct |
229 ms |
1260 KB |
Output is correct |
32 |
Correct |
299 ms |
1260 KB |
Output is correct |
33 |
Correct |
286 ms |
1388 KB |
Output is correct |
34 |
Correct |
293 ms |
1388 KB |
Output is correct |
35 |
Correct |
295 ms |
1388 KB |
Output is correct |
36 |
Correct |
302 ms |
1260 KB |
Output is correct |