結果

問題 No.1572 XI
ユーザー SSRSSSRS
提出日時 2021-06-27 13:43:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,582 ms / 2,000 ms
コード長 1,794 bytes
コンパイル時間 4,309 ms
コンパイル使用メモリ 221,896 KB
実行使用メモリ 175,220 KB
最終ジャッジ日時 2023-09-07 17:41:05
合計ジャッジ時間 20,822 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 160 ms
38,728 KB
testcase_05 AC 800 ms
85,952 KB
testcase_06 AC 609 ms
103,624 KB
testcase_07 AC 16 ms
6,092 KB
testcase_08 AC 109 ms
89,464 KB
testcase_09 AC 237 ms
45,764 KB
testcase_10 AC 189 ms
70,848 KB
testcase_11 AC 36 ms
8,500 KB
testcase_12 AC 182 ms
33,964 KB
testcase_13 AC 46 ms
10,584 KB
testcase_14 AC 162 ms
33,980 KB
testcase_15 AC 17 ms
9,640 KB
testcase_16 AC 124 ms
28,872 KB
testcase_17 AC 13 ms
6,260 KB
testcase_18 AC 45 ms
41,076 KB
testcase_19 AC 180 ms
93,484 KB
testcase_20 AC 121 ms
61,748 KB
testcase_21 AC 678 ms
107,636 KB
testcase_22 AC 750 ms
84,804 KB
testcase_23 AC 8 ms
5,312 KB
testcase_24 AC 2 ms
4,384 KB
testcase_25 AC 1 ms
4,384 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,504 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 232 ms
159,080 KB
testcase_35 AC 186 ms
157,764 KB
testcase_36 AC 489 ms
162,076 KB
testcase_37 AC 1,582 ms
168,000 KB
testcase_38 AC 963 ms
165,136 KB
testcase_39 AC 714 ms
166,232 KB
testcase_40 AC 300 ms
153,480 KB
testcase_41 AC 972 ms
161,552 KB
testcase_42 AC 1,579 ms
163,864 KB
testcase_43 AC 649 ms
161,208 KB
testcase_44 AC 292 ms
175,132 KB
testcase_45 AC 1,167 ms
175,172 KB
testcase_46 AC 1,152 ms
175,188 KB
testcase_47 AC 187 ms
175,128 KB
testcase_48 AC 941 ms
175,220 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> R = {{-1, 3, 1, 4, 2, -1}, {2, -1, 5, 0, -1, 3}, {4, 0, -1, -1, 5, 1}, {1, 5, -1, -1, 0, 4}, {3, -1, 0, 5, -1, 2}, {-1, 2, 4, 1, 3, -1}};
int main(){
  int H, W;
  cin >> H >> W;
  int sy, sx;
  cin >> sy >> sx;
  sy--;
  sx--;
  int gy, gx;
  cin >> gy >> gx;
  gy--;
  gx--;
  vector<vector<char>> A(H, vector<char>(W));
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      cin >> A[i][j];
    }
  }
  queue<tuple<int, int, int, int>> Q;
  Q.push(make_tuple(sy, sx, 0, 1));
  vector<vector<vector<vector<int>>>> d(6, vector<vector<vector<int>>>(6, vector<vector<int>>(H, vector<int>(W, -1))));
  d[0][1][sy][sx] = 0;
  int ans = -1;
  while (!Q.empty()){
    int y = get<0>(Q.front());
    int x = get<1>(Q.front());
    int t = get<2>(Q.front());
    int f = get<3>(Q.front());
    Q.pop();
    if (y == gy && x == gx && t == 0){
      ans = d[t][f][y][x];
      break;
    }
    int r = R[t][f];
    if (y < H - 1){
      if (A[y + 1][x] == '.' && d[5 - f][t][y + 1][x] == -1){
        d[5 - f][t][y + 1][x] = d[t][f][y][x] + 1;
        Q.push(make_tuple(y + 1, x, 5 - f, t));
      }
    }
    if (y > 0){
      if (A[y - 1][x] == '.' && d[f][5 - t][y - 1][x] == -1){
        d[f][5 - t][y - 1][x] = d[t][f][y][x] + 1;
        Q.push(make_tuple(y - 1, x, f, 5 - t));
      }
    }
    if (x < W - 1){
      if (A[y][x + 1] == '.' && d[5 - r][f][y][x + 1] == -1){
        d[5 - r][f][y][x + 1] = d[t][f][y][x] + 1;
        Q.push(make_tuple(y, x + 1, 5 - r, f));
      }
    }
    if (x > 0){
      if (A[y][x - 1] == '.' && d[r][f][y][x - 1] == -1){
        d[r][f][y][x - 1] = d[t][f][y][x] + 1;
        Q.push(make_tuple(y, x - 1, r, f));
      }
    }
  }
  cout << ans << endl;
}
0