結果

問題 No.2412 YOU Grow Bigger!
ユーザー 👑 chro_96chro_96
提出日時 2023-08-11 23:44:20
言語 C
(gcc 12.3.0)
結果
RE  
実行時間 -
コード長 2,660 bytes
コンパイル時間 192 ms
コンパイル使用メモリ 33,404 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-29 14:58:15
合計ジャッジ時間 1,752 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 22 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 34 ms
5,376 KB
testcase_14 AC 24 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 24 ms
5,376 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 3 ms
5,376 KB
testcase_21 WA -
testcase_22 AC 31 ms
5,376 KB
testcase_23 AC 17 ms
5,376 KB
testcase_24 AC 32 ms
5,376 KB
testcase_25 WA -
testcase_26 AC 18 ms
5,376 KB
testcase_27 AC 12 ms
5,376 KB
testcase_28 AC 29 ms
5,376 KB
testcase_29 AC 3 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

int dmap[4][2] = { { -1, 0 }, { 1, 0 }, { 0, -1 }, { 0, 1 } };

int main () {
  int h = 0;
  int w = 0;
  char s[400][401] = {};
  
  int res = 0;
  
  int is_ok = 0;
  
  int r[400][400] = {};
  int org_flag[400][400] = {};
  int flag[400][400] = {};
  
  int q[2400][2] = {};
  int q_hd = 0;
  int q_tl = 0;
  
  res = scanf("%d", &h);
  res = scanf("%d", &w);
  for (int i = 0; i < h; i++) {
    res = scanf("%s", s[i]);
  }
  
  for (int i = 0; i < h-2; i++) {
    for (int j = 0; j < w-2; j++) {
      for (int k = 0; k < 3; k++) {
        for (int l = 0; l < 3; l++) {
          if (s[i+k][j+l] == '#') {
            flag[i][j] = 1;
            org_flag[i][j] = 1;
          }
        }
      }
    }
  }
  
  r[0][0] = 1;
  q[q_tl][0] = 0;
  q[q_tl][1] = 0;
  q_tl++;
  while (q_hd < q_tl) {
    int ci = q[q_hd][0];
    int cj = q[q_hd][1];
    q_hd++;
    for (int i = 0; i < 4; i++) {
      int ni = ci+dmap[i][0];
      int nj = cj+dmap[i][1];
      if (ni >= 0 && ni < h-2 && nj >= 0 && nj < w-2 && flag[ni][nj] == 0 && r[ni][nj] <= 0) {
        r[ni][nj] = 1;
        q[q_tl][0] = ni;
        q[q_tl][1] = nj;
        q_tl++;
      }
    }
  }
  
  if (r[h-3][w-3] <= 0) {
    printf("0\n");
    return 0;
  }
  
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if ((i > 2 || j > 2) && (i < h-3 || j < w-3) && s[i][j] == '.') {
        for (int k = 0; k < 3; k++) {
          for (int l = 0; l < 3; l++) {
            if (i-k >= 0 && i-k < h-2 && j-l >= 0 && j-l < w-2) {
              flag[i-k][j-l] = 1;
            }
          }
        }
        for (int i = 0; i < h-2; i++) {
          for (int j = 0; j < w-2; j++) {
            r[i][j] = 0;
          }
        }
        q_hd = 0;
        q_tl = 0;
        r[0][0] = 1;
        q[q_tl][0] = 0;
        q[q_tl][1] = 0;
        q_tl++;
        while (q_hd < q_tl) {
          int ci = q[q_hd][0];
          int cj = q[q_hd][1];
          q_hd++;
          for (int i = 0; i < 4; i++) {
            int ni = ci+dmap[i][0];
            int nj = cj+dmap[i][1];
            if (ni >= 0 && ni < h-2 && nj >= 0 && nj < w-2 && flag[ni][nj] == 0 && r[ni][nj] <= 0) {
              r[ni][nj] = 1;
              q[q_tl][0] = ni;
              q[q_tl][1] = nj;
              q_tl++;
            }
          }
        }
  
        if (r[h-3][w-3] <= 0) {
          is_ok = 1;
        }
    
        for (int i = 0; i < h-2; i++) {
          for (int j = 0; j < w-2; j++) {
            flag[i][j] = org_flag[i][j];
          }
        }
      }
    }
  }
  
  if (is_ok > 0) {
    printf("1\n");
  } else {
    printf("2\n");
    return 1;
  }
  
  return 0;
}
0