# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
180282 |
2020-01-08T14:53:51 Z |
socho |
Nautilus (BOI19_nautilus) |
C++14 |
|
1000 ms |
888 KB |
#include "bits/stdc++.h"
using namespace std;
int a, b, m;
vector<vector<bool> > grid;
string s;
bool valid(int x, int y) {
// cout << "! " << x << ' ' << y << endl;
if (x < 0 || y < 0) return false;
if (x >= a || y >= b) return false;
return grid[x][y];
}
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
int main() {
cin >> a >> b >> m;
for (int i=0; i<a; i++) {
string s;
cin >> s;
vector<bool> tr(b);
for (int j=0; j<b; j++) {
tr[j] = (s[j] == '.');
}
grid.push_back(tr);
}
cin >> s;
s = ' ' + s;
bool reach[a][b][2];
memset(reach, 0, sizeof reach);
for (int i=0; i<a; i++) {
for (int j=0; j<b; j++) {
reach[i][j][0] = valid(i, j);
}
}
for (int STEP=1; STEP<=m; STEP++) {
// ith step
char st = s[STEP];
for (int i=0; i<a; i++) {
for (int j=0; j<b; j++) {
if (valid(i, j)) {
if (st == 'W') {
reach[i][j][STEP%2] = (valid(i, j+1) && reach[i][j+1][(STEP+1)%2]);
}
else if (st == 'E') {
reach[i][j][STEP%2] = (valid(i, j-1) && reach[i][j-1][(STEP+1)%2]);
}
else if (st == 'N') {
reach[i][j][STEP%2] = (valid(i+1, j) && reach[i+1][j][(STEP+1)%2]);
}
else if (st == 'S') {
reach[i][j][STEP%2] = (valid(i-1, j) && reach[i-1][j][(STEP+1)%2]);
}
else {
reach[i][j][STEP%2] = false;
for (int k=0; k<4; k++) {
reach[i][j][STEP%2] |= (valid(i+dx[k], j+dy[k]) && reach[i+dx[k]][j+dy[k]][(STEP+1)%2]);
}
}
}
else {
reach[i][j][STEP%2] = false;
}
}
}
}
int c = 0;
for (int i=0; i<a; i++) {
for (int j=0; j<b; j++) {
if (reach[i][j][m%2]) c++;
}
}
cout << c << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
376 KB |
Output is correct |
2 |
Correct |
15 ms |
380 KB |
Output is correct |
3 |
Correct |
16 ms |
384 KB |
Output is correct |
4 |
Correct |
17 ms |
376 KB |
Output is correct |
5 |
Correct |
11 ms |
376 KB |
Output is correct |
6 |
Correct |
7 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
376 KB |
Output is correct |
2 |
Correct |
15 ms |
380 KB |
Output is correct |
3 |
Correct |
16 ms |
384 KB |
Output is correct |
4 |
Correct |
17 ms |
376 KB |
Output is correct |
5 |
Correct |
11 ms |
376 KB |
Output is correct |
6 |
Correct |
7 ms |
376 KB |
Output is correct |
7 |
Correct |
17 ms |
376 KB |
Output is correct |
8 |
Correct |
22 ms |
376 KB |
Output is correct |
9 |
Correct |
20 ms |
296 KB |
Output is correct |
10 |
Correct |
13 ms |
376 KB |
Output is correct |
11 |
Correct |
6 ms |
380 KB |
Output is correct |
12 |
Correct |
26 ms |
376 KB |
Output is correct |
13 |
Correct |
29 ms |
376 KB |
Output is correct |
14 |
Correct |
29 ms |
504 KB |
Output is correct |
15 |
Correct |
15 ms |
504 KB |
Output is correct |
16 |
Correct |
8 ms |
420 KB |
Output is correct |
17 |
Correct |
32 ms |
376 KB |
Output is correct |
18 |
Correct |
34 ms |
504 KB |
Output is correct |
19 |
Correct |
27 ms |
376 KB |
Output is correct |
20 |
Correct |
16 ms |
376 KB |
Output is correct |
21 |
Correct |
7 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
376 KB |
Output is correct |
2 |
Correct |
15 ms |
380 KB |
Output is correct |
3 |
Correct |
16 ms |
384 KB |
Output is correct |
4 |
Correct |
17 ms |
376 KB |
Output is correct |
5 |
Correct |
11 ms |
376 KB |
Output is correct |
6 |
Correct |
7 ms |
376 KB |
Output is correct |
7 |
Correct |
17 ms |
376 KB |
Output is correct |
8 |
Correct |
22 ms |
376 KB |
Output is correct |
9 |
Correct |
20 ms |
296 KB |
Output is correct |
10 |
Correct |
13 ms |
376 KB |
Output is correct |
11 |
Correct |
6 ms |
380 KB |
Output is correct |
12 |
Correct |
26 ms |
376 KB |
Output is correct |
13 |
Correct |
29 ms |
376 KB |
Output is correct |
14 |
Correct |
29 ms |
504 KB |
Output is correct |
15 |
Correct |
15 ms |
504 KB |
Output is correct |
16 |
Correct |
8 ms |
420 KB |
Output is correct |
17 |
Correct |
32 ms |
376 KB |
Output is correct |
18 |
Correct |
34 ms |
504 KB |
Output is correct |
19 |
Correct |
27 ms |
376 KB |
Output is correct |
20 |
Correct |
16 ms |
376 KB |
Output is correct |
21 |
Correct |
7 ms |
376 KB |
Output is correct |
22 |
Execution timed out |
1040 ms |
888 KB |
Time limit exceeded |
23 |
Halted |
0 ms |
0 KB |
- |