# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
896136 |
2023-12-31T21:41:10 Z |
box |
Nautilus (BOI19_nautilus) |
C++17 |
|
161 ms |
1112 KB |
#include <bits/stdc++.h>
using namespace std;
#define ar array
#define all(v) begin(v), end(v)
#define sz(v) int(std::size(v))
using i64 = long long;
using u64 = unsigned long long;
using pii = pair<int, int>;
using vi = vector<int>;
const int MAXN = 500, BIT = 64, FULL = 63;
const int NUM = MAXN / BIT + 1;
const i64 FIRST = (1LL << 0), LAST = (1LL << 63);
int N, M, K;
string T;
u64 good[MAXN][NUM];
u64 ok[MAXN][NUM];
u64 transition[4][MAXN][NUM];
bool flip;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> N >> M >> K;
if (N > M) flip = 1;
for (int i = 0; i < (flip ? M : N); i++) for (int j = 0; j < (flip ? N : M); j++)
good[i][j / BIT] |= 1LL << (j & FULL);
for (int i = 0; i < N; i++) {
string S; cin >> S;
for (int j = 0; j < M; j++) if (S[j] == '#') {
if (flip) good[j][i / BIT] ^= 1LL << (i & FULL);
else good[i][j / BIT] ^= 1LL << (j & FULL);
}
}
cin >> T;
for (char &c : T) if (flip && c != '?') {
if (c == 'W') c = 'N';
else if (c == 'E') c = 'S';
else if (c == 'N') c = 'W';
else if (c == 'S') c = 'E';
}
if (flip) swap(N, M);
// reverse(begin(T), end(T));
int BLOCKS = (M - 1) / BIT + 1;
for (int i = 0; i < N; i++) for (int j = 0; j < BLOCKS; j++)
ok[i][j] = good[i][j];
auto print = [&]() {
for (int i = 0; i < N; i++) {
for (int j = 0; j < BLOCKS; j++)
for (int k = 0; k < BIT; k++)
cerr << (ok[i][j] >> k & 1);
cerr << endl;
}
cerr << endl;
};
// print();
for (char c : T) {
static bool f[4];
fill(f, f + 4, false);
if (c == 'S' || c == '?') {
f[0] = 1;
for (int i = 0; i < N; i++) for (int j = 0; j < BLOCKS; j++)
transition[0][i][j] = i == 0 ? 0 : ok[i - 1][j];
}
if (c == 'N' || c == '?') {
f[1] = 1;
for (int i = 0; i < N; i++) for (int j = 0; j < BLOCKS; j++)
transition[1][i][j] = i == N - 1 ? 0 : ok[i + 1][j];
}
if (c == 'E' || c == '?') {
f[2] = 1;
for (int i = 0; i < N; i++) for (int j = 0; j < BLOCKS; j++) {
transition[2][i][j] = ok[i][j] << 1;
if (j && (ok[i][j - 1] & LAST)) transition[2][i][j] |= FIRST;
}
}
if (c == 'W' || c == '?') {
f[3] = 1;
for (int i = 0; i < N; i++) for (int j = 0; j < BLOCKS; j++) {
transition[3][i][j] = ok[i][j] >> 1;
if (j != BLOCKS - 1 && (ok[i][j + 1] & FIRST)) transition[3][i][j] |= LAST;
}
}
for (int i = 0; i < N; i++) for (int j = 0; j < BLOCKS; j++) {
ok[i][j] = 0;
if (f[0]) ok[i][j] |= transition[0][i][j];
if (f[1]) ok[i][j] |= transition[1][i][j];
if (f[2]) ok[i][j] |= transition[2][i][j];
if (f[3]) ok[i][j] |= transition[3][i][j];
ok[i][j] &= good[i][j];
}
// print();
}
int tot = 0;
for (int i = 0; i < N; i++) for (int j = 0; j < M; j++) if (ok[i][j / BIT] >> (j & FULL) & 1)
tot++;
cout << tot << '\n';
}
Compilation message
nautilus.cpp: In function 'int main()':
nautilus.cpp:49:10: warning: variable 'print' set but not used [-Wunused-but-set-variable]
49 | auto print = [&]() {
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
464 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
444 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
464 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
444 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
67 ms |
904 KB |
Output is correct |
23 |
Correct |
84 ms |
900 KB |
Output is correct |
24 |
Correct |
72 ms |
896 KB |
Output is correct |
25 |
Correct |
69 ms |
860 KB |
Output is correct |
26 |
Correct |
68 ms |
856 KB |
Output is correct |
27 |
Correct |
84 ms |
1112 KB |
Output is correct |
28 |
Correct |
129 ms |
860 KB |
Output is correct |
29 |
Correct |
161 ms |
860 KB |
Output is correct |
30 |
Correct |
92 ms |
856 KB |
Output is correct |
31 |
Correct |
80 ms |
860 KB |
Output is correct |
32 |
Correct |
92 ms |
856 KB |
Output is correct |
33 |
Correct |
113 ms |
860 KB |
Output is correct |
34 |
Correct |
130 ms |
860 KB |
Output is correct |
35 |
Correct |
106 ms |
860 KB |
Output is correct |
36 |
Correct |
100 ms |
900 KB |
Output is correct |