結果

問題 No.1572 XI
ユーザー shiomusubi496shiomusubi496
提出日時 2021-06-27 15:09:56
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 403 ms / 2,000 ms
コード長 812 bytes
コンパイル時間 2,290 ms
コンパイル使用メモリ 214,368 KB
実行使用メモリ 91,664 KB
最終ジャッジ日時 2023-09-07 17:58:12
合計ジャッジ時間 11,814 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 81 ms
21,308 KB
testcase_05 AC 191 ms
45,144 KB
testcase_06 AC 228 ms
54,588 KB
testcase_07 AC 6 ms
4,760 KB
testcase_08 AC 191 ms
47,028 KB
testcase_09 AC 90 ms
23,896 KB
testcase_10 AC 150 ms
37,440 KB
testcase_11 AC 12 ms
6,176 KB
testcase_12 AC 65 ms
18,036 KB
testcase_13 AC 15 ms
6,876 KB
testcase_14 AC 67 ms
18,708 KB
testcase_15 AC 14 ms
6,812 KB
testcase_16 AC 55 ms
15,744 KB
testcase_17 AC 5 ms
4,400 KB
testcase_18 AC 82 ms
22,008 KB
testcase_19 AC 207 ms
49,024 KB
testcase_20 AC 128 ms
32,460 KB
testcase_21 AC 233 ms
56,548 KB
testcase_22 AC 184 ms
44,524 KB
testcase_23 AC 5 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 362 ms
82,544 KB
testcase_35 AC 355 ms
81,576 KB
testcase_36 AC 365 ms
83,812 KB
testcase_37 AC 374 ms
86,584 KB
testcase_38 AC 367 ms
86,264 KB
testcase_39 AC 373 ms
87,104 KB
testcase_40 AC 349 ms
79,720 KB
testcase_41 AC 368 ms
83,532 KB
testcase_42 AC 368 ms
84,676 KB
testcase_43 AC 362 ms
83,144 KB
testcase_44 AC 403 ms
91,420 KB
testcase_45 AC 399 ms
90,976 KB
testcase_46 AC 390 ms
91,580 KB
testcase_47 AC 134 ms
90,988 KB
testcase_48 AC 394 ms
91,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define int long long
using namespace std;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
int dr[4][6]={{1,5,2,0,4,3},{4,1,0,3,5,2},{3,0,2,5,4,1},{2,1,5,3,0,4}};
signed main(){
  int H,W; cin>>H>>W;
  int sx,sy; cin>>sx>>sy; sx--; sy--;
  int gx,gy; cin>>gx>>gy; gx--; gy--;
  vector<string> G(H);
  for(int i=0;i<H;i++)cin>>G[i];
  vector<vector<vector<int>>> dist(H,vector<vector<int>>(W,vector<int>(6,-1)));
  dist[sx][sy][0]=0;
  queue<tuple<int,int,int>> Q; Q.push({sx,sy,0});
  while(!Q.empty()){
    auto[x,y,r]=Q.front(); Q.pop();
    for(int i=0;i<4;i++){
      int X=x+dx[i],Y=y+dy[i],R=dr[i][r];
      if(0<=X && X<H && 0<=Y && Y<W && G[X][Y]=='.' && dist[X][Y][R]==-1){
        dist[X][Y][R]=dist[x][y][r]+1;
        Q.push({X,Y,R});
      }
    }
  }
  cout<<dist[gx][gy][0]<<endl;
}
0