#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
int n, m, q;
char a[501][501];
string s;
int in(int i, int j){
return (i >= 1 && j >= 1 && i <= n && j <= m and a[i][j] == '.');
}
map<char, vector<pair<int, int> > >mp;
main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> m >> q;
for(int i = 1;i <= n; i++){
for(int j = 1;j <= m; j++){
cin >> a[i][j];
}
}
mp['N'].push_back({-1, 0});
mp['S'].push_back({1, 0});
mp['E'].push_back({0, 1});
mp['W'].push_back({0, -1});
mp['?'].push_back({-1, 0});
mp['?'].push_back({1, 0});
mp['?'].push_back({0, 1});
mp['?'].push_back({0, -1});
cin >> s;
vector< pair<int, int> > cells;
for(int i = 1;i <= n; i++){
for(int j = 1;j <= m; j++){
if(a[i][j] != '#') cells.push_back({i, j});
}
}
for(char ch : s){
vector<pair<int, int> > new_cells;
for(auto [i, j] : cells){
for(auto [x, y] : mp[ch]){
if(in(i + x, j + y)){
new_cells.push_back({i + x, j + y});
}
}
}
swap(cells, new_cells);
if(new_cells.empty()){
break;
}
sort(all(cells));
cells.erase(unique(all(cells)), cells.end());
}
cout << cells.size();
return 0;
}
Compilation message
nautilus.cpp:19:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
19 | main(){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
1052 KB |
Output is correct |
2 |
Correct |
2 ms |
860 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
0 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
1052 KB |
Output is correct |
2 |
Correct |
2 ms |
860 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
0 ms |
468 KB |
Output is correct |
7 |
Correct |
78 ms |
3140 KB |
Output is correct |
8 |
Correct |
14 ms |
1212 KB |
Output is correct |
9 |
Correct |
4 ms |
692 KB |
Output is correct |
10 |
Correct |
1 ms |
472 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
145 ms |
3272 KB |
Output is correct |
13 |
Correct |
111 ms |
2240 KB |
Output is correct |
14 |
Correct |
57 ms |
1316 KB |
Output is correct |
15 |
Correct |
3 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
185 ms |
2784 KB |
Output is correct |
18 |
Correct |
147 ms |
1840 KB |
Output is correct |
19 |
Correct |
40 ms |
844 KB |
Output is correct |
20 |
Correct |
9 ms |
600 KB |
Output is correct |
21 |
Correct |
1 ms |
548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
1052 KB |
Output is correct |
2 |
Correct |
2 ms |
860 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
0 ms |
468 KB |
Output is correct |
7 |
Correct |
78 ms |
3140 KB |
Output is correct |
8 |
Correct |
14 ms |
1212 KB |
Output is correct |
9 |
Correct |
4 ms |
692 KB |
Output is correct |
10 |
Correct |
1 ms |
472 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
145 ms |
3272 KB |
Output is correct |
13 |
Correct |
111 ms |
2240 KB |
Output is correct |
14 |
Correct |
57 ms |
1316 KB |
Output is correct |
15 |
Correct |
3 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
185 ms |
2784 KB |
Output is correct |
18 |
Correct |
147 ms |
1840 KB |
Output is correct |
19 |
Correct |
40 ms |
844 KB |
Output is correct |
20 |
Correct |
9 ms |
600 KB |
Output is correct |
21 |
Correct |
1 ms |
548 KB |
Output is correct |
22 |
Execution timed out |
1089 ms |
52912 KB |
Time limit exceeded |
23 |
Halted |
0 ms |
0 KB |
- |