結果
| 問題 | 
                            No.1572 XI
                             | 
                    
| コンテスト | |
| ユーザー | 
                             どらら
                         | 
                    
| 提出日時 | 2021-06-27 14:36:16 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 436 ms / 2,000 ms | 
| コード長 | 2,119 bytes | 
| コンパイル時間 | 4,097 ms | 
| コンパイル使用メモリ | 234,236 KB | 
| 実行使用メモリ | 52,992 KB | 
| 最終ジャッジ日時 | 2024-06-25 11:41:45 | 
| 合計ジャッジ時間 | 14,791 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 45 | 
コンパイルメッセージ
main.cpp: In function 'int next_angle(int, int)':
main.cpp:68:1: warning: control reaches end of non-void function [-Wreturn-type]
   68 | }
      | ^
            
            ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;
//using mint = modint1000000007;
//using mint = modint998244353;
static const ll INF = 1e18;
int H, W;
int sy, sx;
int gy, gx;
string field[1005];
ll dist[1005][1005][6];
int vy[4] = {-1,1,0,0};
int vx[4] = {0,0,-1,1};
struct Pos {
  int y, x, a;
  ll dist;
};
int next_angle(int a, int k){
  if(a == 0){
    if(k==0) return 2;
    if(k==1) return 1;
    if(k==2) return 4;
    if(k==3) return 3;
  }
  if(a == 1){
    if(k==0) return 0;
    if(k==1) return 5;
    if(k==2) return 1;
    if(k==3) return 1;
  }
  if(a == 2){
    if(k==0) return 5;
    if(k==1) return 0;
    if(k==2) return 2;
    if(k==3) return 2;
  }
  if(a == 3){
    if(k==0) return 3;
    if(k==1) return 3;
    if(k==2) return 0;
    if(k==3) return 5;
  }
  if(a == 4){
    if(k==0) return 4;
    if(k==1) return 4;
    if(k==2) return 5;
    if(k==3) return 0;
  }
  if(a == 5){
    if(k==0) return 1;
    if(k==1) return 2;
    if(k==2) return 3;
    if(k==3) return 4;
  }
}
int main(){
  cin >> H >> W;
  cin >> sy >> sx;
  sy--;
  sx--;
  cin >> gy >> gx;
  gy--;
  gx--;
  rep(i,H) cin >> field[i];
  rep(i,1005) rep(j,1005) rep(k,6) dist[i][j][k] = INF;
  queue<Pos> que;
  que.push((Pos){sy,sx,0,0LL});
  while(!que.empty()){
    Pos pos = que.front(); que.pop();
    if(dist[pos.y][pos.x][pos.a] != INF) continue;
    dist[pos.y][pos.x][pos.a] = pos.dist;
    rep(k,4){
      int ny = pos.y + vy[k];
      int nx = pos.x + vx[k];
      if(ny<0 || ny>=H || nx<0 || nx>=W) continue;
      if(field[ny][nx] == '#') continue;
      int next_a = next_angle(pos.a, k);
      if(dist[ny][nx][next_a] != INF) continue;
      que.push((Pos){ny,nx,next_a,pos.dist+1});
    }
  }
  if(dist[gy][gx][0] == INF) cout << -1 << endl;
  else cout << dist[gy][gx][0] << endl;
  
  return 0;
}
            
            
            
        
            
どらら