結果

問題 No.1572 XI
ユーザー 👑 emthrmemthrm
提出日時 2021-06-27 13:23:13
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 549 ms / 2,000 ms
コード長 2,191 bytes
コンパイル時間 2,645 ms
コンパイル使用メモリ 216,472 KB
実行使用メモリ 59,384 KB
最終ジャッジ日時 2023-09-07 17:35:04
合計ジャッジ時間 14,233 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 110 ms
15,296 KB
testcase_05 AC 257 ms
30,476 KB
testcase_06 AC 308 ms
35,952 KB
testcase_07 AC 8 ms
4,464 KB
testcase_08 AC 264 ms
31,240 KB
testcase_09 AC 124 ms
16,560 KB
testcase_10 AC 205 ms
25,060 KB
testcase_11 AC 17 ms
5,172 KB
testcase_12 AC 90 ms
12,772 KB
testcase_13 AC 21 ms
5,700 KB
testcase_14 AC 92 ms
13,208 KB
testcase_15 AC 21 ms
5,572 KB
testcase_16 AC 74 ms
11,320 KB
testcase_17 AC 7 ms
4,376 KB
testcase_18 AC 110 ms
15,200 KB
testcase_19 AC 277 ms
32,488 KB
testcase_20 AC 179 ms
22,084 KB
testcase_21 AC 325 ms
36,900 KB
testcase_22 AC 249 ms
29,624 KB
testcase_23 AC 6 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 497 ms
54,152 KB
testcase_35 AC 484 ms
53,564 KB
testcase_36 AC 498 ms
54,600 KB
testcase_37 AC 525 ms
56,916 KB
testcase_38 AC 505 ms
55,936 KB
testcase_39 AC 525 ms
56,444 KB
testcase_40 AC 479 ms
52,256 KB
testcase_41 AC 508 ms
54,752 KB
testcase_42 AC 503 ms
55,524 KB
testcase_43 AC 495 ms
54,324 KB
testcase_44 AC 549 ms
59,384 KB
testcase_45 AC 541 ms
59,036 KB
testcase_46 AC 533 ms
59,020 KB
testcase_47 AC 92 ms
59,028 KB
testcase_48 AC 536 ms
59,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);
  }
} iosetup;

// https://github.com/beet-aizu/library/blob/master/tools/dice.cpp
int roll(int red, int dir) {
  int b[]{3, 1, 2, 0};
  int v[6][4]={{0,3,5,2},
                {0,2,5,3},
                {0,1,5,4},
                {0,4,5,1},
                {1,2,4,3},
                {1,3,4,2}};
  int fs[6]{};
  fs[red] = 1;
  for(int k=0;k<4;k++){
    if(b[k]!=dir) continue;
    int t=fs[v[k][0]];
    fs[v[k][0]]=fs[v[k][1]];
    fs[v[k][1]]=fs[v[k][2]];
    fs[v[k][2]]=fs[v[k][3]];
    fs[v[k][3]]=t;
  }
  REP(i, 6) {
    if (fs[i] == 1) return i;
  }
  return -1;
}

// https://mojacoder.app/users/milkcoffee/contests/mr-contest001/tasks/3
int main() {
  int h, w, sy, sx, gy, gx; cin >> h >> w >> sy >> sx >> gy >> gx; --sy; --sx; --gy; --gx;
  vector<string> s(h); REP(i, h) cin >> s[i];
  vector dist(h, vector(w, vector(6, -1)));
  dist[sy][sx][0] = 0;
  queue<tuple<int, int, int>> que({{sy, sx, 0}});
  while (!que.empty()) {
    auto [i, j, one] = que.front(); que.pop();
    REP(k, 4) {
      int y = i + dy[k], x = j + dx[k];
      if (int nx = roll(one, k);
          0 <= y && y < h && 0 <= x && x < w && s[y][x] == '.' && dist[y][x][nx] == -1) {
        dist[y][x][nx] = dist[i][j][one] + 1;
        que.emplace(y, x, nx);
      }
    }
  }
  cout << dist[gy][gx][0] << '\n';
  return 0;
}
0