# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
723460 | lovrot | Nautilus (BOI19_nautilus) | C++17 | 1077 ms | 1200 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 <cstdio>
#include <cstring>
#pragma GCC optimize("Ofast")
using namespace std;
const int N = 510;
const int lx[4] = {1, -1, 0, 0};
const int ly[4] = {0, 0, -1, 1};
int n, m, q;
bool dp[2][N][N], mat[N][N];
int main() {
scanf("%d%d%d", &n, &m, &q);
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++) {
char c;
scanf(" %c", &c);
dp[0][i][j] = c == '.';
mat[i][j] = !dp[0][i][j];
}
bool flag = 1;
for(int t = 0; t < q; t++) {
char c;
scanf(" %c", &c);
// printf("%c\n", c);
int x = -1;
if(c == 'S') x = 1;
if(c == 'N') x = 0;
if(c == 'W') x = 3;
if(c == 'E') x = 2;
if(x == -1) {
memset(dp[flag], 0, sizeof(dp[flag]));
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
for(int k = 0; k < 4; k++)
dp[flag][i][j] |= !mat[i][j] && dp[!flag][i + lx[k]][j + ly[k]];
} else {
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
dp[flag][i][j] = !mat[i][j] && dp[!flag][i + lx[x]][j + ly[x]];
}
flag ^= 1;
}
int sol = 0;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
sol += dp[!flag][i][j];
printf("%d\n", sol);
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... |