#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define int long long
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
const int N=505;
char a[N][N];
signed main(){
ios_base::sync_with_stdio();
cin.tie(0);cout.tie(0);
int n,m,k;
cin>>n>>m>>k;
set <pair <int,int> > v1,v2;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>a[i][j];
if(a[i][j]=='.')v1.insert({i,j});
}
}
string s;cin>>s;
s=' '+s;
for(int x=0;x<k;x++){
for(auto y : v1){
int i=y.ff,j=y.ss;
if((s[x+1]=='W' or s[x+1]=='?') && j-1>=0 && a[i][j-1]=='.')v2.insert({i,j-1});
if((s[x+1]=='E' or s[x+1]=='?') && j+1<m && a[i][j+1]=='.')v2.insert({i,j+1});
if((s[x+1]=='S' or s[x+1]=='?') && i+1<n && a[i+1][j]=='.')v2.insert({i+1,j});
if((s[x+1]=='N' or s[x+1]=='?') && i-1>=0 && a[i-1][j]=='.')v2.insert({i-1,j});
}
swap(v1,v2);
v2.clear();
}
cout<<v1.size();
}
/*
5 9 7
...##....
..#.##..#
..#....##
.##...#..
....#....
WS?EE??
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
89 ms |
1724 KB |
Output is correct |
2 |
Correct |
10 ms |
1368 KB |
Output is correct |
3 |
Correct |
3 ms |
860 KB |
Output is correct |
4 |
Correct |
2 ms |
860 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
89 ms |
1724 KB |
Output is correct |
2 |
Correct |
10 ms |
1368 KB |
Output is correct |
3 |
Correct |
3 ms |
860 KB |
Output is correct |
4 |
Correct |
2 ms |
860 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
170 ms |
1728 KB |
Output is correct |
8 |
Correct |
25 ms |
968 KB |
Output is correct |
9 |
Correct |
7 ms |
604 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
263 ms |
1724 KB |
Output is correct |
13 |
Correct |
169 ms |
1372 KB |
Output is correct |
14 |
Correct |
95 ms |
1216 KB |
Output is correct |
15 |
Correct |
4 ms |
616 KB |
Output is correct |
16 |
Correct |
1 ms |
448 KB |
Output is correct |
17 |
Correct |
346 ms |
1624 KB |
Output is correct |
18 |
Correct |
216 ms |
1628 KB |
Output is correct |
19 |
Correct |
68 ms |
948 KB |
Output is correct |
20 |
Correct |
19 ms |
604 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
89 ms |
1724 KB |
Output is correct |
2 |
Correct |
10 ms |
1368 KB |
Output is correct |
3 |
Correct |
3 ms |
860 KB |
Output is correct |
4 |
Correct |
2 ms |
860 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
170 ms |
1728 KB |
Output is correct |
8 |
Correct |
25 ms |
968 KB |
Output is correct |
9 |
Correct |
7 ms |
604 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
263 ms |
1724 KB |
Output is correct |
13 |
Correct |
169 ms |
1372 KB |
Output is correct |
14 |
Correct |
95 ms |
1216 KB |
Output is correct |
15 |
Correct |
4 ms |
616 KB |
Output is correct |
16 |
Correct |
1 ms |
448 KB |
Output is correct |
17 |
Correct |
346 ms |
1624 KB |
Output is correct |
18 |
Correct |
216 ms |
1628 KB |
Output is correct |
19 |
Correct |
68 ms |
948 KB |
Output is correct |
20 |
Correct |
19 ms |
604 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Execution timed out |
1068 ms |
32084 KB |
Time limit exceeded |
23 |
Halted |
0 ms |
0 KB |
- |