結果

問題 No.1323 うしらずSwap
ユーザー 👑 NachiaNachia
提出日時 2020-12-20 17:41:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,064 bytes
コンパイル時間 2,212 ms
コンパイル使用メモリ 207,256 KB
実行使用メモリ 42,548 KB
最終ジャッジ日時 2023-10-21 10:47:48
合計ジャッジ時間 12,086 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,692 KB
testcase_01 AC 2 ms
7,692 KB
testcase_02 AC 2 ms
7,688 KB
testcase_03 AC 2 ms
7,688 KB
testcase_04 AC 2 ms
7,788 KB
testcase_05 AC 3 ms
7,788 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 2 ms
7,692 KB
testcase_11 WA -
testcase_12 AC 2 ms
7,728 KB
testcase_13 AC 2 ms
7,688 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 221 ms
42,504 KB
testcase_17 AC 168 ms
42,496 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 216 ms
42,500 KB
testcase_21 AC 232 ms
42,504 KB
testcase_22 AC 156 ms
42,504 KB
testcase_23 AC 219 ms
42,500 KB
testcase_24 AC 157 ms
42,496 KB
testcase_25 AC 238 ms
42,500 KB
testcase_26 AC 179 ms
42,500 KB
testcase_27 AC 184 ms
42,504 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 253 ms
42,524 KB
testcase_34 AC 249 ms
42,544 KB
testcase_35 AC 249 ms
42,540 KB
testcase_36 AC 245 ms
42,532 KB
testcase_37 AC 241 ms
42,524 KB
testcase_38 AC 231 ms
42,548 KB
testcase_39 AC 240 ms
42,544 KB
testcase_40 AC 240 ms
42,548 KB
testcase_41 AC 239 ms
42,544 KB
testcase_42 AC 232 ms
42,528 KB
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 AC 11 ms
42,048 KB
testcase_59 AC 3 ms
7,780 KB
testcase_60 AC 11 ms
42,052 KB
testcase_61 AC 3 ms
7,852 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//#include<atcoder/all>
//using namespace atcoder;
#include<bits/stdc++.h>
using namespace std;
using LL=long long;
using ULL=unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

int H,W;
int Ay,Ax,By,Bx;
bool block[3<<9][3<<9];
int D[3<<9][3<<9][2];
int P[3<<9][3<<9][2];
int dx[4][2]={{-1,0},{0,-1},{1,0},{0,1}};

struct QueueNode{ int x,y,t; };

int main(){
	cin>>H>>W>>Ay>>Ax>>By>>Bx; Ay--; Ax--; By--; Bx--;
	rep(y,H) rep(x,W) rep(t,2){ D[x][y][t]=-1; P[x][y][t]=-1; }
	rep(y,H) rep(x,W){ char c; cin>>c; block[x][y]=(c=='#'); }
	queue<QueueNode> Q;
	D[Ax][Ay][0]=0;
	Q.push({Ax,Ay,0});
	while(Q.size()){
		auto q = Q.front(); Q.pop();
		rep(i,4){
			auto nx=q; nx.x+=dx[i][0]; nx.y+=dx[i][1];
			if(block[nx.x][nx.y]) continue;
			while(nx.t<2) if(D[nx.x][nx.y][nx.t]!=-1) nx.t++; else break;
			if(nx.t==2) continue;
			if(P[q.x][q.y][q.t]==(i^2)) continue;
			D[nx.x][nx.y][nx.t]=D[q.x][q.y][q.t]+1;
			P[nx.x][nx.y][nx.t]=i;
			Q.push(nx);
		}
	}
	if(D[Bx][By][1]==-1) cout<<-1<<endl;
	else cout<<(D[Bx][By][0]+D[Bx][By][1])<<endl;
	return 0;
}
0