結果

問題 No.1572 XI
ユーザー SSRSSSRS
提出日時 2021-06-27 13:40:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,794 bytes
コンパイル時間 2,672 ms
コンパイル使用メモリ 222,552 KB
実行使用メモリ 590,872 KB
最終ジャッジ日時 2023-09-07 17:40:37
合計ジャッジ時間 34,008 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 304 ms
124,916 KB
testcase_05 AC 1,052 ms
286,928 KB
testcase_06 AC 996 ms
345,012 KB
testcase_07 AC 30 ms
12,260 KB
testcase_08 AC 472 ms
295,816 KB
testcase_09 AC 437 ms
140,904 KB
testcase_10 AC 471 ms
230,660 KB
testcase_11 AC 63 ms
21,680 KB
testcase_12 AC 333 ms
101,688 KB
testcase_13 AC 84 ms
26,300 KB
testcase_14 AC 304 ms
105,572 KB
testcase_15 AC 47 ms
25,316 KB
testcase_16 AC 247 ms
86,096 KB
testcase_17 AC 19 ms
10,172 KB
testcase_18 AC 199 ms
127,180 KB
testcase_19 AC 556 ms
309,072 KB
testcase_20 AC 366 ms
197,904 KB
testcase_21 AC 1,034 ms
358,692 KB
testcase_22 AC 1,045 ms
279,088 KB
testcase_23 AC 14 ms
8,860 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 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,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 MLE -
testcase_35 MLE -
testcase_36 MLE -
testcase_37 TLE -
testcase_38 MLE -
testcase_39 MLE -
testcase_40 MLE -
testcase_41 MLE -
testcase_42 TLE -
testcase_43 MLE -
testcase_44 MLE -
testcase_45 MLE -
testcase_46 MLE -
testcase_47 MLE -
testcase_48 MLE -
権限があれば一括ダウンロードができます

ソースコード

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(H, vector<vector<vector<int>>>(W, vector<vector<int>>(6, vector<int>(6, -1))));
  d[sy][sx][0][1] = 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[y][x][t][f];
      break;
    }
    int r = R[t][f];
    if (y < H - 1){
      if (A[y + 1][x] == '.' && d[y + 1][x][5 - f][t] == -1){
        d[y + 1][x][5 - f][t] = d[y][x][t][f] + 1;
        Q.push(make_tuple(y + 1, x, 5 - f, t));
      }
    }
    if (y > 0){
      if (A[y - 1][x] == '.' && d[y - 1][x][f][5 - t] == -1){
        d[y - 1][x][f][5 - t] = d[y][x][t][f] + 1;
        Q.push(make_tuple(y - 1, x, f, 5 - t));
      }
    }
    if (x < W - 1){
      if (A[y][x + 1] == '.' && d[y][x + 1][5 - r][f] == -1){
        d[y][x + 1][5 - r][f] = d[y][x][t][f] + 1;
        Q.push(make_tuple(y, x + 1, 5 - r, f));
      }
    }
    if (x > 0){
      if (A[y][x - 1] == '.' && d[y][x - 1][r][f] == -1){
        d[y][x - 1][r][f] = d[y][x][t][f] + 1;
        Q.push(make_tuple(y, x - 1, r, f));
      }
    }
  }
  cout << ans << endl;
}
0