Submission #529741

# Submission time Handle Problem Language Result Execution time Memory
529741 2022-02-23T14:55:22 Z c28dnv9q3 Nautilus (BOI19_nautilus) C++17
100 / 100
43 ms 400 KB
#include <cstdio>
#include <iostream>

#define DEBUG if(false)

const int N_MAX = 512;
const int M_MAX = 5005;

int R, C, M;

uint64_t map[4096];
uint64_t cur[2][4096];

void printcur(int k) {
  for (int i = 0; i <= R + 1; i++) {
    for (int j = 0; j <= C + 1; j++) {
      putchar((cur[k][i*8 + j/64] & (1ULL << (j%64))) ? '#' : '.');
    }
    putchar('\n');
  }
  putchar('\n');
}

int main() {
  std::cin >> R >> C >> M;
  
  for (int i = 0; i < R; i++) {
    std::string s;
    std::cin >> s;
    for (int j = 0; j < C; j++) {
      if (s[j] == '.') {
        map[(i+1)*8 + (j+1)/64] |= 1ULL << ((j+1) % 64);
      }
    }
  }
  /*for (int i = 0; i < R + 2; i++) {
    map[i][0] = false;
    map[i][C+1] = false;
  }
  for (int j = 0; j < C + 2; j++) {
    map[0][j] = false;
    map[R+1][j] = false;
  }*/

  int k = 0;
  for (int i = 0; i < 4096; i++) {
    cur[k][i] = map[i];
  }

  DEBUG printf("Map at beginning\n");
  DEBUG printcur(k);

  std::string instr;
  std::cin >> instr;

  for (int i = 0; i < instr.size(); i++) {
    char c = instr[i];
    k = 1-k;
    DEBUG printf("INSTRUCTION %c (k=%d)\n", c, k);
    switch (c) {
      case 'N':
        for (int i = 8; i < 4096-8; i++) {
          cur[k][i] = cur[1-k][i+8] & map[i];
        }
        break;
      case 'E':
        for (int i = 8; i < 4096-8; i++) {
          uint64_t main = cur[1-k][i] << 1ULL;
          main &= ~1ULL;
          main |= (cur[1-k][i-1] >> 63ULL) & 1ULL;
          cur[k][i] = main & map[i];
        }
        break;
      case 'S': 
        for (int i = 8; i < 4096-8; i++) {
          cur[k][i] = cur[1-k][i-8] & map[i];
        }
        break;
      case 'W': 
        for (int i = 8; i < 4096-8; i++) {
          uint64_t main = cur[1-k][i] >> 1ULL;
          main &= ~(1ULL << 63ULL);
          main |= (cur[1-k][i+1]  & 1ULL) << 63ULL;
          cur[k][i] = main & map[i];
        }
        break;
      case '?':
        for (int i = 8; i < 4096-8; i++) {
          uint64_t m = 0;
          m |= cur[1-k][i+8];
          m |= cur[1-k][i-8];
          {
            uint64_t main = cur[1-k][i] << 1ULL;
            main &= ~1ULL;
            main |= (cur[1-k][i-1] >> 63ULL) & 1ULL;
            m |= main;
          }
          {
            uint64_t main = cur[1-k][i] >> 1ULL;
            main &= ~(1ULL << 63ULL);
            main |= (cur[1-k][i+1]  & 1ULL) << 63ULL;
            m |= main;
          }
          cur[k][i] = m & map[i];
        }
        break;
    }
    DEBUG printcur(k);
  }

  int num = 0;
  for (int i = 0; i < 4096; i++) {
    for (int j = 0; j < 64; j++) {
      num += (cur[k][i] & (1ULL << j)) ? 1 : 0;
    }
  }

  std::cout << num << std::endl;
}

Compilation message

nautilus.cpp: In function 'int main()':
nautilus.cpp:56:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |   for (int i = 0; i < instr.size(); i++) {
      |                   ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 1 ms 296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 1 ms 296 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 2 ms 332 KB Output is correct
13 Correct 3 ms 332 KB Output is correct
14 Correct 2 ms 332 KB Output is correct
15 Correct 3 ms 360 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 3 ms 332 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
20 Correct 2 ms 332 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 1 ms 296 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 2 ms 332 KB Output is correct
13 Correct 3 ms 332 KB Output is correct
14 Correct 2 ms 332 KB Output is correct
15 Correct 3 ms 360 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 3 ms 332 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
20 Correct 2 ms 332 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 30 ms 332 KB Output is correct
23 Correct 29 ms 332 KB Output is correct
24 Correct 29 ms 304 KB Output is correct
25 Correct 28 ms 400 KB Output is correct
26 Correct 36 ms 332 KB Output is correct
27 Correct 36 ms 332 KB Output is correct
28 Correct 40 ms 332 KB Output is correct
29 Correct 38 ms 332 KB Output is correct
30 Correct 36 ms 384 KB Output is correct
31 Correct 35 ms 332 KB Output is correct
32 Correct 41 ms 332 KB Output is correct
33 Correct 42 ms 300 KB Output is correct
34 Correct 42 ms 380 KB Output is correct
35 Correct 43 ms 380 KB Output is correct
36 Correct 41 ms 360 KB Output is correct