結果
| 問題 | 
                            No.1572 XI
                             | 
                    
| コンテスト | |
| ユーザー | 
                             Nachia
                         | 
                    
| 提出日時 | 2021-06-27 13:34:30 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 844 ms / 2,000 ms | 
| コード長 | 1,644 bytes | 
| コンパイル時間 | 733 ms | 
| コンパイル使用メモリ | 80,624 KB | 
| 最終ジャッジ日時 | 2025-01-22 14:03:57 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 45 | 
ソースコード
#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;
            
            
            
        
            
Nachia