#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// Ofast, O0, O1, O2, O3, unroll-loops, fast-math, trapv
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define Mp make_pair
#define sep ' '
#define endl '\n'
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define kill(res) cout << res << '\n', exit(0);
#define set_dec(x) cout << fixed << setprecision(x);
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("input.txt", "r", stdin) ; freopen("output.txt", "w", stdout);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll N = 507;
const ll Q = 5007;
const ll Mod = 1e9 + 7;
ll n, m, q;
string s;
bitset<N> arr[N], dp[2][N];
int main(){
fast_io;
cin >> n >> m >> q;
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
char c; cin >> c;
if(c == '.') arr[i][j] = dp[0][i][j] = 1;
}
}
cin >> s; s = "$" + s;
for(int i = 1; i <= q; i++){
int nw = i % 2;
int pr = 1 - nw;
if(s[i] == 'E'){
for(int i = 0; i < n; i++) dp[nw][i] = (dp[pr][i] << 1) & arr[i];
}
if(s[i] == 'W'){
for(int i = 0; i < n; i++) dp[nw][i] = (dp[pr][i] >> 1) & arr[i];
}
if(s[i] == 'N'){
for(int i = 0; i < n-1; i++) dp[nw][i] = dp[pr][i+1] & arr[i];
dp[nw][n-1].reset();
}
if(s[i] == 'S'){
for(int i = 1; i < n; i++) dp[nw][i] = dp[pr][i-1] & arr[i];
dp[nw][0].reset();
}
if(s[i] == '?'){
for(int i = 1; i < n-1; i++) dp[nw][i] = arr[i] & (dp[pr][i-1] | dp[pr][i+1] | (dp[pr][i] >> 1) | (dp[pr][i] << 1));
dp[nw][0] = arr[0] & (dp[pr][0+1] | (dp[pr][0] >> 1) | (dp[pr][0] << 1));
dp[nw][n-1] = arr[n-1] & (dp[pr][n-2] | (dp[pr][n-1] >> 1) | (dp[pr][n-1] << 1));
}
/*
cout << i << endl;
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
cout << dp[nw][i][j];
}
cout << endl;
}
cout << endl;
*/
}
ll res = 0;
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
if(dp[q%2][i][j]) res++;
cout << res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
24 ms |
736 KB |
Output is correct |
23 |
Correct |
25 ms |
604 KB |
Output is correct |
24 |
Correct |
25 ms |
604 KB |
Output is correct |
25 |
Correct |
24 ms |
604 KB |
Output is correct |
26 |
Correct |
23 ms |
604 KB |
Output is correct |
27 |
Correct |
34 ms |
600 KB |
Output is correct |
28 |
Correct |
35 ms |
600 KB |
Output is correct |
29 |
Correct |
36 ms |
816 KB |
Output is correct |
30 |
Correct |
35 ms |
604 KB |
Output is correct |
31 |
Correct |
36 ms |
604 KB |
Output is correct |
32 |
Correct |
42 ms |
604 KB |
Output is correct |
33 |
Correct |
42 ms |
824 KB |
Output is correct |
34 |
Correct |
43 ms |
856 KB |
Output is correct |
35 |
Correct |
45 ms |
604 KB |
Output is correct |
36 |
Correct |
47 ms |
780 KB |
Output is correct |