# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
159632 | DrSwad | Nautilus (BOI19_nautilus) | C++17 | 1084 ms | 64720 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;
#ifdef LOCAL
#include "debug.h"
#endif
typedef long long ll;
typedef unsigned int uint;
typedef pair<int, int> pii;
#define x first
#define y second
#define size(a) (int)a.size()
const int N = 505, M = 5005;
enum dir {
UP,
RIGHT,
DOWN,
LEFT,
ALL
};
int r, c, m;
char cell[N][N];
bool vis[M][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++) {
for (int _r = 1; _r <= r; _r++) {
for (int _c = 1; _c <= c; _c++) {
if (!vis[i - 1][_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][_x][_y] = true;
}
}
}
}
cout << accumulate(&vis[m][0][0], &vis[m][0][0] + sizeof(vis[m]), 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... |