Submission #529711

# Submission time Handle Problem Language Result Execution time Memory
529711 2022-02-23T13:59:29 Z c28dnv9q3 Nautilus (BOI19_nautilus) C++17
66 / 100
1000 ms 1040 KB
#include <cstdio>
#include <iostream>

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

int R, C, M;

bool map[N_MAX][N_MAX];
bool cur[2][N_MAX][N_MAX];

void printcur(int k) {
  for (int i = 0; i <= R + 1; i++) {
    for (int j = 0; j <= C + 1; j++) {
      putchar(cur[k][i][j] ? '#' : '.');
    }
    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++) {
      map[i+1][j+1] = s[j] == '.';
    }
  }
  /*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 = 1; i <= R; i++) {
    for (int j = 1; j <= C; j++) {
      cur[k][i][j] = map[i][j];
    }
  }

  //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 = 1; i <= R; i++) {
          for (int j = 1; j <= C; j++) {
            cur[k][i][j] = cur[1-k][i+1][j] && map[i][j];
          }
        }
        break;
      case 'E': 
        for (int i = 1; i <= R; i++) {
          for (int j = 1; j <= C; j++) {
            cur[k][i][j] = cur[1-k][i][j-1] && map[i][j];
          }
        }
        break;
      case 'S': 
        for (int i = 1; i <= R; i++) {
          for (int j = 1; j <= C; j++) {
            cur[k][i][j] = cur[1-k][i-1][j] && map[i][j];
          }
        }
        break;
      case 'W': 
        for (int i = 1; i <= R; i++) {
          for (int j = 1; j <= C; j++) {
            cur[k][i][j] = cur[1-k][i][j+1] && map[i][j];
          }
        }
        break;
      case '?':
        for (int i = 1; i <= R; i++) {
          for (int j = 1; j <= C; j++) {
            cur[k][i][j] = (
              cur[1-k][i-1][j] || cur[1-k][i+1][j] || 
              cur[1-k][i][j-1] || cur[1-k][i][j+1]
            ) && map[i][j];
          }
        }
        break;
    }
    //printcur(k);
  }

  int num = 0;
  for (int i = 1; i <= R; i++) {
    for (int j = 1; j <= C; j++) {
      num += cur[k][i][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 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 460 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 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 460 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 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 4 ms 332 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 2 ms 332 KB Output is correct
13 Correct 4 ms 332 KB Output is correct
14 Correct 7 ms 412 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 3 ms 332 KB Output is correct
19 Correct 6 ms 452 KB Output is correct
20 Correct 4 ms 332 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 460 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 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 4 ms 332 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 2 ms 332 KB Output is correct
13 Correct 4 ms 332 KB Output is correct
14 Correct 7 ms 412 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 3 ms 332 KB Output is correct
19 Correct 6 ms 452 KB Output is correct
20 Correct 4 ms 332 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 741 ms 1040 KB Output is correct
23 Execution timed out 1097 ms 972 KB Time limit exceeded
24 Halted 0 ms 0 KB -