#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=(a);i<(b);i++)
#define fore(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
#define F first
#define S second
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
void amin(ll &a, ll b){ a=min(a,b); }
void amax(ll &a, ll b){ a=max(a,b); }
void YES(){cout<<"YES\n";} void NO(){cout<<"NO\n";}
void SD(int t=0){ cout<<"PASSED "<<t<<endl; }
const ll INF = ll(1e18);
const int MOD = 998244353;
const bool DEBUG = 0;
const int MAXN = 505;
const int MAXK = 5005;
int n,m,K;
string s;
string A[MAXN];
bitset<MAXN> dp[MAXK][MAXN], a[MAXN];
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
cin>>n>>m>>K;
forn(i,0,n) cin>>A[i];
cin>>s;
forn(i,0,n){
forn(j,0,m){
dp[0][i][j]=a[i][j]=(A[i][j]=='.');
}
}
fore(k,1,K)
{
if(s[k-1]=='N'){
forn(i,0,n-1) dp[k][i] = dp[k-1][i+1] & a[i];
}
if(s[k-1]=='S'){
forn(i,1,n) dp[k][i] = dp[k-1][i-1] & a[i];
}
if(s[k-1]=='E'){
forn(i,0,n) dp[k][i] = (dp[k-1][i]<<1) & a[i];
}
if(s[k-1]=='W'){
forn(i,0,n) dp[k][i] = (dp[k-1][i]>>1) & a[i];
}
if(s[k-1]=='?'){
forn(i,1,n) dp[k][i] |= dp[k-1][i-1] & a[i];
forn(i,0,n-1) dp[k][i] |= dp[k-1][i+1] & a[i];
forn(i,0,n) dp[k][i] |= (dp[k-1][i]<<1) & a[i];
forn(i,0,n) dp[k][i] |= (dp[k-1][i]>>1) & a[i];
}
}
int ans=0;
forn(i,0,n){
ans += dp[K][i].count();
}
cout<<ans<<'\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1408 KB |
Output is correct |
2 |
Correct |
1 ms |
1408 KB |
Output is correct |
3 |
Correct |
1 ms |
1408 KB |
Output is correct |
4 |
Correct |
1 ms |
1408 KB |
Output is correct |
5 |
Correct |
1 ms |
1408 KB |
Output is correct |
6 |
Correct |
1 ms |
1408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1408 KB |
Output is correct |
2 |
Correct |
1 ms |
1408 KB |
Output is correct |
3 |
Correct |
1 ms |
1408 KB |
Output is correct |
4 |
Correct |
1 ms |
1408 KB |
Output is correct |
5 |
Correct |
1 ms |
1408 KB |
Output is correct |
6 |
Correct |
1 ms |
1408 KB |
Output is correct |
7 |
Correct |
1 ms |
1408 KB |
Output is correct |
8 |
Correct |
1 ms |
1408 KB |
Output is correct |
9 |
Correct |
1 ms |
1408 KB |
Output is correct |
10 |
Correct |
1 ms |
1408 KB |
Output is correct |
11 |
Correct |
2 ms |
1408 KB |
Output is correct |
12 |
Correct |
1 ms |
1408 KB |
Output is correct |
13 |
Correct |
2 ms |
1408 KB |
Output is correct |
14 |
Correct |
1 ms |
1408 KB |
Output is correct |
15 |
Correct |
1 ms |
1408 KB |
Output is correct |
16 |
Correct |
1 ms |
1408 KB |
Output is correct |
17 |
Correct |
2 ms |
1408 KB |
Output is correct |
18 |
Correct |
2 ms |
1408 KB |
Output is correct |
19 |
Correct |
2 ms |
1408 KB |
Output is correct |
20 |
Correct |
2 ms |
1408 KB |
Output is correct |
21 |
Correct |
1 ms |
1408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1408 KB |
Output is correct |
2 |
Correct |
1 ms |
1408 KB |
Output is correct |
3 |
Correct |
1 ms |
1408 KB |
Output is correct |
4 |
Correct |
1 ms |
1408 KB |
Output is correct |
5 |
Correct |
1 ms |
1408 KB |
Output is correct |
6 |
Correct |
1 ms |
1408 KB |
Output is correct |
7 |
Correct |
1 ms |
1408 KB |
Output is correct |
8 |
Correct |
1 ms |
1408 KB |
Output is correct |
9 |
Correct |
1 ms |
1408 KB |
Output is correct |
10 |
Correct |
1 ms |
1408 KB |
Output is correct |
11 |
Correct |
2 ms |
1408 KB |
Output is correct |
12 |
Correct |
1 ms |
1408 KB |
Output is correct |
13 |
Correct |
2 ms |
1408 KB |
Output is correct |
14 |
Correct |
1 ms |
1408 KB |
Output is correct |
15 |
Correct |
1 ms |
1408 KB |
Output is correct |
16 |
Correct |
1 ms |
1408 KB |
Output is correct |
17 |
Correct |
2 ms |
1408 KB |
Output is correct |
18 |
Correct |
2 ms |
1408 KB |
Output is correct |
19 |
Correct |
2 ms |
1408 KB |
Output is correct |
20 |
Correct |
2 ms |
1408 KB |
Output is correct |
21 |
Correct |
1 ms |
1408 KB |
Output is correct |
22 |
Correct |
145 ms |
159096 KB |
Output is correct |
23 |
Correct |
149 ms |
159096 KB |
Output is correct |
24 |
Correct |
144 ms |
159096 KB |
Output is correct |
25 |
Correct |
143 ms |
159096 KB |
Output is correct |
26 |
Correct |
143 ms |
159096 KB |
Output is correct |
27 |
Correct |
188 ms |
159096 KB |
Output is correct |
28 |
Correct |
185 ms |
159096 KB |
Output is correct |
29 |
Correct |
187 ms |
159096 KB |
Output is correct |
30 |
Correct |
188 ms |
159096 KB |
Output is correct |
31 |
Correct |
185 ms |
159096 KB |
Output is correct |
32 |
Correct |
216 ms |
159096 KB |
Output is correct |
33 |
Correct |
214 ms |
159096 KB |
Output is correct |
34 |
Correct |
218 ms |
159092 KB |
Output is correct |
35 |
Correct |
231 ms |
158984 KB |
Output is correct |
36 |
Correct |
225 ms |
159096 KB |
Output is correct |