結果

問題 No.1572 XI
ユーザー どららどらら
提出日時 2021-06-27 14:36:16
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 371 ms / 2,000 ms
コード長 2,119 bytes
コンパイル時間 3,868 ms
コンパイル使用メモリ 231,708 KB
実行使用メモリ 52,912 KB
最終ジャッジ日時 2023-09-07 17:53:57
合計ジャッジ時間 12,916 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
50,812 KB
testcase_01 AC 14 ms
50,760 KB
testcase_02 AC 14 ms
50,712 KB
testcase_03 AC 15 ms
50,716 KB
testcase_04 AC 89 ms
51,240 KB
testcase_05 AC 185 ms
51,372 KB
testcase_06 AC 219 ms
51,776 KB
testcase_07 AC 19 ms
51,100 KB
testcase_08 AC 193 ms
51,616 KB
testcase_09 AC 97 ms
51,224 KB
testcase_10 AC 152 ms
51,384 KB
testcase_11 AC 25 ms
51,004 KB
testcase_12 AC 74 ms
51,024 KB
testcase_13 AC 27 ms
50,872 KB
testcase_14 AC 75 ms
51,104 KB
testcase_15 AC 28 ms
50,828 KB
testcase_16 AC 64 ms
51,012 KB
testcase_17 AC 19 ms
50,800 KB
testcase_18 AC 89 ms
51,376 KB
testcase_19 AC 198 ms
51,828 KB
testcase_20 AC 133 ms
51,276 KB
testcase_21 AC 227 ms
51,656 KB
testcase_22 AC 183 ms
51,800 KB
testcase_23 AC 17 ms
50,900 KB
testcase_24 AC 15 ms
50,828 KB
testcase_25 AC 15 ms
50,808 KB
testcase_26 AC 15 ms
50,752 KB
testcase_27 AC 14 ms
50,716 KB
testcase_28 AC 15 ms
51,016 KB
testcase_29 AC 14 ms
50,816 KB
testcase_30 AC 14 ms
50,876 KB
testcase_31 AC 14 ms
50,760 KB
testcase_32 AC 15 ms
50,876 KB
testcase_33 AC 14 ms
50,756 KB
testcase_34 AC 340 ms
51,860 KB
testcase_35 AC 331 ms
51,860 KB
testcase_36 AC 333 ms
52,036 KB
testcase_37 AC 357 ms
51,944 KB
testcase_38 AC 348 ms
52,780 KB
testcase_39 AC 355 ms
52,752 KB
testcase_40 AC 327 ms
51,864 KB
testcase_41 AC 345 ms
51,900 KB
testcase_42 AC 343 ms
51,844 KB
testcase_43 AC 338 ms
51,848 KB
testcase_44 AC 370 ms
52,852 KB
testcase_45 AC 369 ms
52,876 KB
testcase_46 AC 371 ms
52,800 KB
testcase_47 AC 33 ms
52,912 KB
testcase_48 AC 369 ms
52,856 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int next_angle(int, int)’ 内:
main.cpp:68:1: 警告: 制御が非 void 関数の終りに到達しました [-Wreturn-type]
   68 | }
      | ^

ソースコード

diff #

#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;
}

0