結果

問題 No.1572 XI
ユーザー 👑 NachiaNachia
提出日時 2021-06-27 13:34:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 908 ms / 2,000 ms
コード長 1,644 bytes
コンパイル時間 917 ms
コンパイル使用メモリ 82,568 KB
実行使用メモリ 312,828 KB
最終ジャッジ日時 2023-09-07 17:38:03
合計ジャッジ時間 20,740 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 184 ms
68,180 KB
testcase_05 AC 440 ms
152,196 KB
testcase_06 AC 516 ms
191,352 KB
testcase_07 AC 15 ms
7,992 KB
testcase_08 AC 442 ms
157,980 KB
testcase_09 AC 206 ms
78,732 KB
testcase_10 AC 343 ms
126,580 KB
testcase_11 AC 29 ms
12,664 KB
testcase_12 AC 149 ms
58,836 KB
testcase_13 AC 37 ms
16,520 KB
testcase_14 AC 155 ms
60,308 KB
testcase_15 AC 35 ms
15,200 KB
testcase_16 AC 126 ms
51,544 KB
testcase_17 AC 12 ms
8,328 KB
testcase_18 AC 184 ms
72,284 KB
testcase_19 AC 458 ms
165,676 KB
testcase_20 AC 296 ms
110,468 KB
testcase_21 AC 533 ms
197,352 KB
testcase_22 AC 415 ms
149,780 KB
testcase_23 AC 11 ms
6,836 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 845 ms
284,764 KB
testcase_35 AC 800 ms
282,044 KB
testcase_36 AC 813 ms
288,496 KB
testcase_37 AC 869 ms
298,884 KB
testcase_38 AC 839 ms
294,172 KB
testcase_39 AC 863 ms
296,940 KB
testcase_40 AC 800 ms
274,592 KB
testcase_41 AC 834 ms
287,424 KB
testcase_42 AC 834 ms
292,332 KB
testcase_43 AC 822 ms
287,824 KB
testcase_44 AC 908 ms
311,156 KB
testcase_45 AC 906 ms
311,748 KB
testcase_46 AC 894 ms
311,052 KB
testcase_47 AC 659 ms
294,540 KB
testcase_48 AC 892 ms
312,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)


int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,-1,0,1 };

int ddice[6][4] = {
  {3,2,1,4},
  {0,1,5,1},
  {2,5,2,0},
  {5,3,0,3},
  {4,0,4,5},
  {1,4,3,2}
};

int H,W;
int sy,sx, gy,gx;
int blocks[1000][1000];
vector<vector<int>> E;

int Vid(int y,int x,int dice){
  return (y*W + x) * 6 + dice;
}

int main(){
  cin >> H >> W;
  cin >> sy >> sx >> gy >> gx;
  sy--; sx--; gy--; gx--;
  rep(y,H) rep(x,W){
    char c; cin >> c;
    if(c == '.') blocks[y][x] = 0;
    else blocks[y][x] = 1;
  }

  E.resize(H*W*6);

  rep(y,H) rep(x,W) rep(d,6) rep(to,4){
    int ny = y + dy[to];
    int nx = x + dx[to];
    int nd = ddice[d][to];
    //cout << "d = " << d << ", to = " << to << ", nd = " << nd << endl;
    if(ny < 0 || H <= ny) continue;
    if(nx < 0 || W <= nx) continue;
    if(blocks[y][x]) continue;
    if(blocks[ny][nx]) continue;
    E[Vid(y,x,d)].push_back(Vid(ny,nx,nd));
  }

  vector<int> D(H*W*6,-1);
  vector<int> I;
  D[Vid(sy,sx,0)] = 0;
  I.push_back(Vid(sy,sx,0));
  for(int i=0; i<I.size(); i++){
    int p = I[i];
    for(int e : E[p]) if(D[e] == -1){
      D[e] = D[p] + 1;
      I.push_back(e);
    }
  }

  rep(y,H){
    rep(x,W){
      //rep(d,6) cout << D[Vid(y,x,d)] << " ";
      //cout << "  ";
    }
    //cout << endl;
  }
  //cout << endl;

  cout << D[Vid(gy,gx,0)] << endl;
  return 0;
}

struct ios_do_not_sync{
  ios_do_not_sync(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
  }
} ios_do_not_sync_inst;
0