結果

問題 No.1572 XI
ユーザー risujirohrisujiroh
提出日時 2021-06-27 13:43:54
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 244 ms / 2,000 ms
コード長 1,328 bytes
コンパイル時間 2,413 ms
コンパイル使用メモリ 211,892 KB
実行使用メモリ 77,904 KB
最終ジャッジ日時 2023-09-07 17:41:27
合計ジャッジ時間 7,081 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 30 ms
16,036 KB
testcase_05 AC 131 ms
41,004 KB
testcase_06 AC 103 ms
42,704 KB
testcase_07 AC 6 ms
4,484 KB
testcase_08 AC 17 ms
16,520 KB
testcase_09 AC 53 ms
21,516 KB
testcase_10 AC 34 ms
19,160 KB
testcase_11 AC 10 ms
5,564 KB
testcase_12 AC 44 ms
20,612 KB
testcase_13 AC 14 ms
8,480 KB
testcase_14 AC 36 ms
14,172 KB
testcase_15 AC 5 ms
4,804 KB
testcase_16 AC 29 ms
12,788 KB
testcase_17 AC 4 ms
4,380 KB
testcase_18 AC 7 ms
8,736 KB
testcase_19 AC 31 ms
19,220 KB
testcase_20 AC 22 ms
15,576 KB
testcase_21 AC 106 ms
43,000 KB
testcase_22 AC 123 ms
40,312 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 36 ms
28,512 KB
testcase_35 AC 26 ms
26,200 KB
testcase_36 AC 78 ms
38,404 KB
testcase_37 AC 244 ms
76,912 KB
testcase_38 AC 149 ms
51,236 KB
testcase_39 AC 117 ms
51,568 KB
testcase_40 AC 50 ms
31,028 KB
testcase_41 AC 148 ms
50,536 KB
testcase_42 AC 243 ms
75,636 KB
testcase_43 AC 107 ms
50,380 KB
testcase_44 AC 47 ms
34,920 KB
testcase_45 AC 186 ms
77,904 KB
testcase_46 AC 187 ms
77,136 KB
testcase_47 AC 25 ms
27,580 KB
testcase_48 AC 152 ms
53,132 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

int main() {
  using namespace std;
  cin.tie(nullptr)->sync_with_stdio(false);
  int h, w;
  cin >> h >> w;
  int si, sj;
  cin >> si >> sj;
  --si, --sj;
  int ti, tj;
  cin >> ti >> tj;
  --ti, --tj;
  vector<string> s(h);
  for (auto&& e : s) cin >> e;
  constexpr array di{1, 0, -1, 0};
  constexpr array dj{0, 1, 0, -1};
  array<array<int, 4>, 6> get_nk;
  get_nk[0] = {1, 2, 3, 4};
  get_nk[1] = {5, 1, 0, 1};
  get_nk[2] = {2, 5, 2, 0};
  get_nk[3] = {0, 3, 5, 3};
  get_nk[4] = {4, 0, 4, 5};
  get_nk[5] = {3, 4, 1, 2};
  vector dist(h, vector<array<int, 6>>(w));
  for (int i = 0; i < h; ++i)
    for (int j = 0; j < w; ++j) dist[i][j].fill(-1);
  vector<tuple<int, int, int>> que{{si, sj, 0}};
  dist[si][sj][0] = 0;
  for (int z = 0; z < int(size(que)); ++z) {
    auto [i, j, k] = que[z];
    if (i == ti and j == tj and k == 0) {
      cout << dist[i][j][k] << '\n';
      exit(0);
    }
    for (int d : {0, 1, 2, 3}) {
      int ni = i + di[d];
      int nj = j + dj[d];
      if (ni < 0 or ni >= h or nj < 0 or nj >= w or s[ni][nj] == '#') continue;
      int nk = get_nk[k][d];
      if (dist[ni][nj][nk] == -1) {
        dist[ni][nj][nk] = dist[i][j][k] + 1;
        que.emplace_back(ni, nj, nk);
      }
    }
  }
  cout << "-1\n";
}
0