#include <bits/stdc++.h>
#define suiii ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define co cout<<
//#pragma GCC optimize("O3,Ofast,unroll-loops")
//#pragma GCC target("avx2,sse3,sse4,avx")
using namespace std;
//stuff
ll n,m,q;
string s[105];
string que;
ll vis[105][105];
ll rem[105][105][105];
void rec(ll i,ll j,ll idx){
if(i>=n||i<0||j>=m||j<0) return;
if(s[i][j]=='#'||rem[i][j][idx]) return;
if(idx==q){
vis[i][j]=1;
return;
}
rem[i][j][idx]=1;
if(que[idx]=='N'||que[idx]=='?') rec(i-1,j,idx+1);
if(que[idx]=='S'||que[idx]=='?') rec(i+1,j,idx+1);
if(que[idx]=='E'||que[idx]=='?') rec(i,j+1,idx+1);
if(que[idx]=='W'||que[idx]=='?') rec(i,j-1,idx+1);
}
void solve(){
cin>>n>>m>>q;
for(int i=0;i<n;i++) cin>>s[i];
cin>>que;
ll cnt=0;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
rec(i,j,0);
}
}
for(int i=0;i<n;i++) for(int j=0;j<m;j++) cnt+=vis[i][j];
co cnt<<'\n';
}
int main()
{
suiii
int tt=1;
// cin>>tt;
while(tt--){
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
9052 KB |
Output is correct |
2 |
Correct |
5 ms |
8796 KB |
Output is correct |
3 |
Correct |
4 ms |
8580 KB |
Output is correct |
4 |
Correct |
4 ms |
8028 KB |
Output is correct |
5 |
Correct |
3 ms |
5980 KB |
Output is correct |
6 |
Correct |
0 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
9052 KB |
Output is correct |
2 |
Correct |
5 ms |
8796 KB |
Output is correct |
3 |
Correct |
4 ms |
8580 KB |
Output is correct |
4 |
Correct |
4 ms |
8028 KB |
Output is correct |
5 |
Correct |
3 ms |
5980 KB |
Output is correct |
6 |
Correct |
0 ms |
604 KB |
Output is correct |
7 |
Correct |
16 ms |
9048 KB |
Output is correct |
8 |
Correct |
7 ms |
8796 KB |
Output is correct |
9 |
Correct |
4 ms |
8160 KB |
Output is correct |
10 |
Correct |
3 ms |
5980 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
20 ms |
9048 KB |
Output is correct |
13 |
Correct |
25 ms |
9052 KB |
Output is correct |
14 |
Correct |
18 ms |
8796 KB |
Output is correct |
15 |
Correct |
3 ms |
6120 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
32 ms |
9044 KB |
Output is correct |
18 |
Correct |
23 ms |
9304 KB |
Output is correct |
19 |
Correct |
9 ms |
8284 KB |
Output is correct |
20 |
Correct |
4 ms |
6316 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
9052 KB |
Output is correct |
2 |
Correct |
5 ms |
8796 KB |
Output is correct |
3 |
Correct |
4 ms |
8580 KB |
Output is correct |
4 |
Correct |
4 ms |
8028 KB |
Output is correct |
5 |
Correct |
3 ms |
5980 KB |
Output is correct |
6 |
Correct |
0 ms |
604 KB |
Output is correct |
7 |
Correct |
16 ms |
9048 KB |
Output is correct |
8 |
Correct |
7 ms |
8796 KB |
Output is correct |
9 |
Correct |
4 ms |
8160 KB |
Output is correct |
10 |
Correct |
3 ms |
5980 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
20 ms |
9048 KB |
Output is correct |
13 |
Correct |
25 ms |
9052 KB |
Output is correct |
14 |
Correct |
18 ms |
8796 KB |
Output is correct |
15 |
Correct |
3 ms |
6120 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
32 ms |
9044 KB |
Output is correct |
18 |
Correct |
23 ms |
9304 KB |
Output is correct |
19 |
Correct |
9 ms |
8284 KB |
Output is correct |
20 |
Correct |
4 ms |
6316 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Runtime error |
1 ms |
860 KB |
Execution killed with signal 11 |
23 |
Halted |
0 ms |
0 KB |
- |