# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1269065 | ducdev | Nautilus (BOI19_nautilus) | C++17 | 130 ms | 800 KiB |
// Author: 4uckd3v - Nguyen Cao Duc
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX_N = 500;
const int MAX_K = 5000;
const int MOD = 1e9 + 7;
int m, n, k;
string dir;
bitset<MAX_N + 5> nxt[MAX_N + 5], cur[MAX_N + 5], ban[MAX_N + 5], mask;
char a[MAX_N + 5][MAX_N + 5];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
if (fopen("MAIN.INP", "r")) {
freopen("MAIN.INP", "r", stdin);
freopen("MAIN.OUT", "w", stdout);
};
cin >> m >> n >> k;
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++) {
cin >> a[i][j];
if (a[i][j] == '.')
cur[i].set(j);
else
ban[i].set(j);
};
};
cin >> dir;
dir = " " + dir;
for (int i = 1; i <= n; i++) mask.set(i);
int res = 0;
for (int i = 1; i <= k; i++) {
for (int j = 1; j <= m; j++) nxt[j].reset();
for (int j = 1; j <= m; j++) {
if (dir[i] == 'W' || dir[i] == '?') nxt[j] |= (cur[j] >> 1);
if (dir[i] == 'E' || dir[i] == '?') nxt[j] |= (cur[j] << 1);
if (dir[i] == 'S' || dir[i] == '?') nxt[j] |= cur[j - 1];
if (dir[i] == 'N' || dir[i] == '?') nxt[j] |= cur[j + 1];
nxt[j] &= mask;
nxt[j] &= ~ban[j];
};
for (int j = 1; j <= m; j++) swap(nxt[j], cur[j]);
};
for (int i = 1; i <= m; i++) res += cur[i].count();
cout << res << '\n';
};
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... |