Submission #529739

# Submission time Handle Problem Language Result Execution time Memory
529739 2022-02-23T14:51:07 Z c28dnv9q3 Nautilus (BOI19_nautilus) C++17
100 / 100
85 ms 680 KB
#include <stdio.h>

typedef unsigned long long llong;

llong grid[8][505];
llong dp[2][8][505];

int main() {
    int R, C, M;
    scanf("%d %d %d", &R, &C, &M);
    int Rc = (R + 63) / 64;

    for(int r = 0; r < R; r++) {
        for(int c = 0; c < C; c++) {
            char chr;
            for(chr = getchar(); chr != '.' && chr != '#'; chr = getchar());
            if(chr == '.') {
                grid[r/64][c] |= 1ull << (r % 64);
                dp[0][r/64][c] |= 1ull << (r % 64);
            }
        }
    }

    int g = 1, pg = 0;
    for(int i = 0; i < M; i++) {
        char m;
        for(m = getchar();
            m != 'N' &&
            m != 'E' &&
            m != 'S' &&
            m != 'W' &&
            m != '?'
        ; m = getchar());

        for(int rc = 0; rc < Rc; rc++) {
            for(int c = 0; c < C; c++) {
                dp[g][rc][c] = 0;

                if((m == '?' || m == 'N')) dp[g][rc][c] |= (dp[pg][rc][c] >> 1) | ((rc < Rc-1) ? (dp[pg][rc+1][c] << 63) : 0);
                if((m == '?' || m == 'S')) dp[g][rc][c] |= (dp[pg][rc][c] << 1) | ((rc > 0) ? (dp[pg][rc-1][c] >> 63) : 0);

                if((m == '?' || m == 'E') && c > 0)   dp[g][rc][c] |= dp[pg][rc][c-1];
                if((m == '?' || m == 'W') && c < C-1) dp[g][rc][c] |= dp[pg][rc][c+1];

                dp[g][rc][c] &= grid[rc][c];
            }
        }

        // printf("%d %c:\n", i, m);
        // for(int r = 0; r < R; r++) {
        //     int rc = r/64, i = r%64;
        //     for(int c = 0; c < C; c++) {
        //         if(!(grid[rc][c] & (1 << i))) putchar('#');
        //         else if(dp[g][rc][c] & (1 << i)) putchar('X');
        //         else putchar('.');
        //     }
        //     puts("");
        // }
        // puts("");

        pg = g;
        g = (g+1) % 2;
    }

    int pc = 0;
    for(int r = 0; r < R; r++) {
        for(int c = 0; c < C; c++) {
            if(dp[pg][r/64][c] & (1ull << (r % 64))) pc++;
        }
    }
    printf("%d\n", pc);

    return 0;
}

Compilation message

nautilus.cpp: In function 'int main()':
nautilus.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     scanf("%d %d %d", &R, &C, &M);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 292 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 292 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 284 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 0 ms 288 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 292 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 284 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 0 ms 288 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 52 ms 424 KB Output is correct
23 Correct 56 ms 480 KB Output is correct
24 Correct 54 ms 604 KB Output is correct
25 Correct 56 ms 596 KB Output is correct
26 Correct 51 ms 540 KB Output is correct
27 Correct 59 ms 544 KB Output is correct
28 Correct 85 ms 600 KB Output is correct
29 Correct 60 ms 596 KB Output is correct
30 Correct 65 ms 600 KB Output is correct
31 Correct 61 ms 588 KB Output is correct
32 Correct 74 ms 680 KB Output is correct
33 Correct 68 ms 600 KB Output is correct
34 Correct 66 ms 532 KB Output is correct
35 Correct 84 ms 580 KB Output is correct
36 Correct 67 ms 540 KB Output is correct