結果

問題 No.2412 YOU Grow Bigger!
ユーザー SSRSSSRS
提出日時 2023-08-11 22:06:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 6,000 ms
コード長 1,521 bytes
コンパイル時間 1,760 ms
コンパイル使用メモリ 181,008 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-13 13:21:12
合計ジャッジ時間 2,977 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000;
int main(){
  int H, W;
  cin >> H >> W;
  vector<vector<char>> S(H + 2, vector<char>(W + 2, '#'));
  for (int i = 1; i <= H; i++){
    for (int j = 1; j <= W; j++){
      cin >> S[i][j];
    }
  }
  vector<vector<int>> d(H + 2, vector<int>(W + 2, -1));
  deque<tuple<int, int, int>> dq;
  for (int i = 4; i < H + 2; i++){
    dq.push_back(make_tuple(0, i, 0));
  }
  for (int i = 1; i < W - 2; i++){
    dq.push_back(make_tuple(0, H + 1, i));
  }
  while (!dq.empty()){
    int c = get<0>(dq.front());
    int x = get<1>(dq.front());
    int y = get<2>(dq.front());
    dq.pop_front();
    if (d[x][y] == -1){
      d[x][y] = c;
      for (int i = -3; i <= 3; i++){
        for (int j = -3; j <= 3; j++){
          if (abs(i) + abs(j) < 6){
            int x2 = x + i;
            int y2 = y + j;
            if (0 <= x2 && x2 < H + 2 && 0 <= y2 && y2 < W + 2){
              if (d[x2][y2] == -1){
                if (!(x2 < 4 && y2 < 4) && !(x2 >= H - 2 && y2 >= W - 2)){
                  if (S[x2][y2] == '#'){
                    dq.push_front(make_tuple(c, x2, y2));
                  } else {
                    dq.push_back(make_tuple(c + 1, x2, y2));
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  int ans = INF;
  for (int i = 4; i < W + 2; i++){
    ans = min(ans, d[0][i]);
  }
  for (int i = 1; i < H - 2; i++){
    ans = min(ans, d[i][W + 1]);
  }
  cout << ans << endl;
}
0