Submission #529719

# Submission time Handle Problem Language Result Execution time Memory
529719 2022-02-23T14:20:46 Z c28dnv9q3 Nautilus (BOI19_nautilus) C++17
0 / 100
1 ms 332 KB
#include <cstdio>
#include <iostream>

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];
  }

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

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

  for (int i = 0; i < instr.size(); i++) {
    char c = instr[i];
    k = 1-k;
    // printf("INSTRUCTION %c (k=%d)\n", c, k);
    switch (c) {
      case 'N':
        for (int i = 0; i < 4096-8; i++) {
          cur[k][i] = cur[1-k][i+8] & map[i];
        }
        break;
      case 'E':
        for (int i = 0; i < 4096-1; i++) {
          uint64_t main = cur[1-k][i] << 1ULL;
          uint64_t cp = cur[1-k][i+1] >> 63ULL;
          cur[k][i] = (main | cp) & map[i];
        }
        cur[k][4095] = (cur[1-k][4095] << 1ULL) & map[4095];
        break;
      case 'S': 
        for (int i = 8; i < 4096; i++) {
          cur[k][i] = cur[1-k][i-8] & map[i];
        }
        break;
      case 'W': 
        cur[k][i] = (cur[1-k][0] >> 1ULL) & map[0];
        for (int i = 1; i < 4096; i++) {
          uint64_t main = cur[1-k][i] >> 1ULL;
          uint64_t cp = cur[1-k][i-1] & 1ULL;
          cur[k][i] = (main | (cp << 63ULL)) & map[i];
        }
        break;
      case '?':
        for (int i = 0; i < 4096; i++) {
          uint64_t m = 0;
          if (i < 4096-8)
            m |= cur[1-k][i+8];
          if (i >= 8)
            m |= cur[1-k][i-8];
          if (i >= 1) {
            uint64_t main = cur[1-k][i] >> 1ULL;
            uint64_t cp = cur[1-k][i-1] & 1ULL;
            m |= (main | (cp << 63ULL));
          }
          if (i < 4096-1) {
            uint64_t main = cur[1-k][i] << 1ULL;
            uint64_t cp = cur[1-k][i+1] >> 63ULL;
            m |= main | cp;
          }
          cur[k][i] = m & map[i];
        }
        break;
    }
    // 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:54:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |   for (int i = 0; i < instr.size(); i++) {
      |                   ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -