#include <bits/stdc++.h>
// #pragma GCC optimize ("Ofast,unroll-loops")
// #pragma GCC target ("avx2")
using namespace std;
typedef long long ll;
typedef pair<int, int> pp;
#define er(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << endl
#define per(i,r,l) for(int i = (r); i >= (l); i--)
#define rep(i,l,r) for(int i = (l); i < (r); i++)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define pb push_back
#define ss second
#define ff first
void err(istringstream *iss){}template<typename T,typename ...Args> void err(istringstream *iss,const T &_val, const Args&...args){string _name;*iss>>_name;if(_name.back()==',')_name.pop_back();cerr<<_name<<" = "<<_val<<", ",err(iss,args...);}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod = 1e9 + 7, maxn = 5e2 + 1, maxk = 101, lg = 21, inf = ll(1e9) + 5;
ll pw(ll a,ll b,ll md=mod){if(!b)return 1;ll k=pw(a,b>>1ll);return k*k%md*(b&1ll?a:1)%md;}
bool dp[maxn][maxn], nw[maxn][maxn], is[maxn][maxn];
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
int main(){
cin.tie(0) -> sync_with_stdio(0);
int n, m, l; cin >> n >> m >> l;
rep(i,0,n) rep(j,0,m){
char c; cin >> c;
is[i][j] = dp[i][j] = c == '.';
}
int ans = 0;
rep(i,0,l){
char c; cin >> c;
int t = 0;
if(c == 'W') t = 1;
if(c == 'N') t = 2;
if(c == 'E') t = 3;
if(c == '?') t = 4;
if(t == 4){
rep(r,0,n) rep(c,0,m) if(is[r][c]){
nw[r][c] = false;
rep(d,0,4){
int x = r + dx[d], y = c + dy[d];
if(x >= 0 && x < n && y >= 0 && y < m) nw[r][c] |= dp[x][y];
}
}
}else{
rep(r,0,n) rep(c,0,m) if(is[r][c]){
nw[r][c] = false;
int x = r + dx[t], y = c + dy[t];
if(x >= 0 && x < n && y >= 0 && y < m) nw[r][c] |= dp[x][y];
}
}
rep(r,0,n) rep(c,0,m) dp[r][c] = nw[r][c], ans += (i==l-1?dp[r][c]:0);
}
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
468 KB |
Output is correct |
2 |
Correct |
5 ms |
468 KB |
Output is correct |
3 |
Correct |
6 ms |
468 KB |
Output is correct |
4 |
Correct |
6 ms |
468 KB |
Output is correct |
5 |
Correct |
4 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
468 KB |
Output is correct |
2 |
Correct |
5 ms |
468 KB |
Output is correct |
3 |
Correct |
6 ms |
468 KB |
Output is correct |
4 |
Correct |
6 ms |
468 KB |
Output is correct |
5 |
Correct |
4 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
6 ms |
468 KB |
Output is correct |
8 |
Correct |
7 ms |
468 KB |
Output is correct |
9 |
Correct |
8 ms |
468 KB |
Output is correct |
10 |
Correct |
5 ms |
468 KB |
Output is correct |
11 |
Correct |
3 ms |
340 KB |
Output is correct |
12 |
Correct |
9 ms |
500 KB |
Output is correct |
13 |
Correct |
12 ms |
468 KB |
Output is correct |
14 |
Correct |
10 ms |
468 KB |
Output is correct |
15 |
Correct |
5 ms |
500 KB |
Output is correct |
16 |
Correct |
4 ms |
344 KB |
Output is correct |
17 |
Correct |
11 ms |
496 KB |
Output is correct |
18 |
Correct |
10 ms |
468 KB |
Output is correct |
19 |
Correct |
9 ms |
468 KB |
Output is correct |
20 |
Correct |
5 ms |
504 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
468 KB |
Output is correct |
2 |
Correct |
5 ms |
468 KB |
Output is correct |
3 |
Correct |
6 ms |
468 KB |
Output is correct |
4 |
Correct |
6 ms |
468 KB |
Output is correct |
5 |
Correct |
4 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
6 ms |
468 KB |
Output is correct |
8 |
Correct |
7 ms |
468 KB |
Output is correct |
9 |
Correct |
8 ms |
468 KB |
Output is correct |
10 |
Correct |
5 ms |
468 KB |
Output is correct |
11 |
Correct |
3 ms |
340 KB |
Output is correct |
12 |
Correct |
9 ms |
500 KB |
Output is correct |
13 |
Correct |
12 ms |
468 KB |
Output is correct |
14 |
Correct |
10 ms |
468 KB |
Output is correct |
15 |
Correct |
5 ms |
500 KB |
Output is correct |
16 |
Correct |
4 ms |
344 KB |
Output is correct |
17 |
Correct |
11 ms |
496 KB |
Output is correct |
18 |
Correct |
10 ms |
468 KB |
Output is correct |
19 |
Correct |
9 ms |
468 KB |
Output is correct |
20 |
Correct |
5 ms |
504 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Execution timed out |
1086 ms |
1304 KB |
Time limit exceeded |
23 |
Halted |
0 ms |
0 KB |
- |