# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1265827 | mingga | Nautilus (BOI19_nautilus) | C++20 | 86 ms | 548 KiB |
// Author: caption_mingle
#include "bits/stdc++.h"
using namespace std;
#define ln "\n"
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define ll long long
const int mod = 1e9 + 7;
const int inf = 2e9;
int n, m, k, idd[150];
pair<int, int> d[4] = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};
bitset<505> f[2][505], a[505];
signed main() {
cin.tie(0) -> sync_with_stdio(0);
#define task ""
if(fopen(task ".INP", "r")) {
freopen(task ".INP", "r", stdin);
freopen(task ".OUT", "w", stdout);
}
cin >> n >> m >> k;
idd['N'] = 1;
idd['S'] = 0;
idd['E'] = 3;
idd['W'] = 2;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
char c; cin >> c;
f[0][i][j] = (c == '.');
a[i][j] = f[0][i][j];
}
}
string s; cin >> s;
for(int t = 1; t <= k; t++) {
char c = s[t - 1];
int id = t & 1;
if(c == '?') {
for(int i = 1; i <= n; i++) {
f[id][i] = (f[id ^ 1][i] >> 1) | (f[id ^ 1][i] << 1);
if(i > 1) f[id][i] |= f[id ^ 1][i - 1];
if(i < n) f[id][i] |= f[id ^ 1][i + 1];
f[id][i] &= a[i];
}
} else if(c == 'N') {
for(int i = 1; i < n; i++) {
f[id][i] = f[id ^ 1][i + 1] & a[i];
}
f[id][n].reset();
} else if(c == 'S') {
f[id][1].reset();
for(int i = 2; i <= n; i++) {
f[id][i] = f[id ^ 1][i - 1] & a[i];
}
} else if(c == 'E') {
for(int i = 1; i <= n; i++) f[id][i] = (f[id ^ 1][i] << 1) & a[i];
} else {
for(int i = 1; i <= n; i++) f[id][i] = (f[id ^ 1][i] >> 1) & a[i];
}
// cerr << "STEP " << t << ln;
// for(int i = 1; i <= n; i++) {
// for(int j = 1; j <= m; j++) {
// cerr << f[id][i][j];
// }
// cerr << ln;
// }
}
int ans = 0;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
ans += f[k & 1][i][j];
}
}
cout << ans << ln;
cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC;
}
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... |