//BOI 2019 NAUTILUS
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <bitset>
#define MAXR 550
#define MAXC 550
#define MAXM 5500
using namespace std;
int R, C, M;
char RAWDAT[MAXR][MAXC];
bitset < MAXC > SEA[MAXR];
bitset < MAXC > CUR[MAXR];
bitset < MAXC > NCUR[MAXR];
bitset < MAXC > BCUR[MAXR];
void cpy_bl(bitset<MAXC>* d, bitset<MAXC>* s, int c) {
for (int i = 0; i < c; ++i)
d[i] = s[i];
}
void or_bl(bitset<MAXC>* d, bitset<MAXC>* s, int c) {
for (int i = 0; i < c; ++i)
d[i] |= s[i];
}
void west() {
for (int r = 0; r < R; ++r)
NCUR[r] = (CUR[r] << 1) & SEA[r];
}
void east() {
for (int r = 0; r < R; ++r) {
NCUR[r] = (CUR[r] >> 1) & SEA[r];
NCUR[r].reset(C);
}
}
void north() {
for (int r = 1; r < R; ++r)
NCUR[r - 1] = CUR[r] & SEA[r - 1];
NCUR[R - 1].reset();
}
void south() {
for (int r = 0; r < R - 1; ++r) {
NCUR[r + 1] = CUR[r] & SEA[r + 1];
}
NCUR[0].reset();
}
void anymove() {
for (int r = 0; r < R; ++r)
BCUR[r].reset();
north();
or_bl(BCUR, NCUR, R);
south();
or_bl(BCUR, NCUR, R);
east();
or_bl(BCUR, NCUR, R);
west();
or_bl(NCUR, BCUR, R);
}
void move(char c) {
switch (c) {
case 'N':
north();
break;
case 'W':
west();
break;
case 'S':
south();
break;
case 'E':
east();
break;
case '?':
anymove();
break;
}
for (int r = 0; r < R; ++r)
CUR[r] = NCUR[r];
}
char Q[MAXM];
int main() {
(void)scanf("%d%d%d", &R, &C, &M);
for (int r = 0; r < R; ++r) {
(void)scanf(" %s", RAWDAT[r]);
for (int c = 0; c < C; ++c) {
SEA[r].set(C-c-1, RAWDAT[r][c] == '.');
}
}
for (int r = 0; r < R; ++r)
CUR[r] = SEA[r];
scanf(" %s", Q);
#ifdef DEBUG
for (int i = 0; i < R; ++i) {
printf("%9s\n", CUR[i].to_string().c_str());
}
#endif
for (int i = 0; i < M; ++i) {
move(Q[i]);
#ifdef DEBUG
printf("\n\n");
for (int i = 0; i < R; ++i) {
printf("%9s\n", CUR[i].to_string().c_str());
}
#endif
}
int c = 0;
for (int i = 0; i < R; ++i) {
c += CUR[i].count();
}
printf("%d\n", c);
}
Compilation message
nautilus.cpp: In function 'int main()':
nautilus.cpp:90:13: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
90 | (void)scanf("%d%d%d", &R, &C, &M);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
nautilus.cpp:92:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
92 | (void)scanf(" %s", RAWDAT[r]);
| ~~~~~^~~~~~~~~~~~~~~~~~
nautilus.cpp:99:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
99 | scanf(" %s", Q);
| ~~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
600 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 |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 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 |
432 KB |
Output is correct |
21 |
Correct |
1 ms |
592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
600 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 |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 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 |
432 KB |
Output is correct |
21 |
Correct |
1 ms |
592 KB |
Output is correct |
22 |
Correct |
88 ms |
860 KB |
Output is correct |
23 |
Correct |
90 ms |
1076 KB |
Output is correct |
24 |
Correct |
86 ms |
1080 KB |
Output is correct |
25 |
Correct |
84 ms |
860 KB |
Output is correct |
26 |
Correct |
83 ms |
1084 KB |
Output is correct |
27 |
Correct |
147 ms |
1084 KB |
Output is correct |
28 |
Correct |
147 ms |
1080 KB |
Output is correct |
29 |
Correct |
148 ms |
860 KB |
Output is correct |
30 |
Correct |
149 ms |
860 KB |
Output is correct |
31 |
Correct |
148 ms |
860 KB |
Output is correct |
32 |
Correct |
216 ms |
856 KB |
Output is correct |
33 |
Correct |
197 ms |
1080 KB |
Output is correct |
34 |
Correct |
190 ms |
1076 KB |
Output is correct |
35 |
Correct |
197 ms |
1080 KB |
Output is correct |
36 |
Correct |
194 ms |
860 KB |
Output is correct |