# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
159572 | DrSwad | Nautilus (BOI19_nautilus) | C++17 | 1058 ms | 1272 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
const int N = 505, M = 5005;
enum dir {
UP,
RIGHT,
DOWN,
LEFT,
ALL
};
int r, c, m;
char cell[N][N];
bool vis[2][N][N];
dir moves[M];
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
int main() {
#ifdef LOCAL
freopen("in", "r", stdin);
freopen("out", "w", stdout);
#endif
scanf("%d %d %d", &r, &c, &m);
for (int i = 1; i <= r; i++) {
scanf("%s", cell[i] + 1);
}
char s[M];
scanf("%s", s + 1);
for (int i = 1; i <= m; i++) {
switch (s[i]) {
case 'N':
moves[i] = UP;
break;
case 'E':
moves[i] = RIGHT;
break;
case 'S':
moves[i] = DOWN;
break;
case 'W':
moves[i] = LEFT;
break;
default:
moves[i] = ALL;
break;
}
}
for (int _r = 1; _r <= r; _r++) {
for (int _c = 1; _c <= c; _c++) {
vis[0][_r][_c] = cell[_r][_c] == '.';
}
}
for (int i = 1; i <= m; i++) {
fill(&vis[i % 2][0][0], &vis[i % 2 + 1][0][0], false);
for (int _r = 1; _r <= r; _r++) {
for (int _c = 1; _c <= c; _c++) {
if (!vis[(i - 1) % 2][_r][_c]) continue;
for (int d = 0; d < 4; d++) {
if (d != moves[i] && moves[i] != ALL) continue;
int _x = _r + dx[d];
int _y = _c + dy[d];
if (_x < 1 || r < _x || _y < 1 || c < _y || cell[_x][_y] != '.') continue;
vis[i % 2][_x][_y] = true;
}
}
}
}
cout << accumulate(&vis[m % 2][0][0], &vis[m % 2 + 1][0][0], 0) << endl;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |