結果

問題 No.1572 XI
ユーザー 👑 kmjpkmjp
提出日時 2021-07-05 22:50:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 200 ms / 2,000 ms
コード長 1,713 bytes
コンパイル時間 2,182 ms
コンパイル使用メモリ 205,536 KB
実行使用メモリ 28,444 KB
最終ジャッジ日時 2023-09-14 04:16:41
合計ジャッジ時間 7,598 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 24 ms
11,512 KB
testcase_05 AC 106 ms
18,304 KB
testcase_06 AC 81 ms
24,240 KB
testcase_07 AC 5 ms
4,380 KB
testcase_08 AC 10 ms
22,076 KB
testcase_09 AC 46 ms
25,276 KB
testcase_10 AC 26 ms
25,472 KB
testcase_11 AC 8 ms
4,416 KB
testcase_12 AC 35 ms
22,768 KB
testcase_13 AC 11 ms
10,296 KB
testcase_14 AC 28 ms
17,112 KB
testcase_15 AC 4 ms
4,536 KB
testcase_16 AC 24 ms
20,812 KB
testcase_17 AC 5 ms
12,016 KB
testcase_18 AC 7 ms
22,952 KB
testcase_19 AC 22 ms
24,064 KB
testcase_20 AC 17 ms
25,384 KB
testcase_21 AC 85 ms
22,356 KB
testcase_22 AC 104 ms
21,992 KB
testcase_23 AC 3 ms
8,000 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 2 ms
4,384 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 20 ms
27,316 KB
testcase_35 AC 14 ms
27,760 KB
testcase_36 AC 56 ms
27,476 KB
testcase_37 AC 199 ms
28,104 KB
testcase_38 AC 121 ms
27,160 KB
testcase_39 AC 87 ms
27,508 KB
testcase_40 AC 32 ms
26,852 KB
testcase_41 AC 119 ms
27,272 KB
testcase_42 AC 200 ms
28,176 KB
testcase_43 AC 80 ms
28,192 KB
testcase_44 AC 28 ms
28,164 KB
testcase_45 AC 144 ms
28,444 KB
testcase_46 AC 147 ms
28,208 KB
testcase_47 AC 11 ms
28,136 KB
testcase_48 AC 119 ms
28,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int H,W;
int SY,SX,GY,GX;
string S[1010];
int D[1010][1010][6];

int dy[4]={0,-1,0,1};
int dx[4]={-1,0,1,0};
int to[4][6]={
	{1,5,2,0,4,3}, //l
	{4,1,0,3,5,2}, //u
	{3,0,2,5,4,1}, //r
	{2,1,5,3,0,4}, //d
};

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>W;
	cin>>SY>>SX;
	cin>>GY>>GX;
	SY--,SX--,GY--,GX--;
	FOR(y,H) cin>>S[y];
	FOR(y,H) FOR(x,W) FOR(i,6) D[y][x][i]=1<<30;
	queue<int> Q;
	D[SY][SX][0]=0;
	Q.push(SY*1000+SX);
	while(Q.size()) {
		int cy=Q.front()%1000000/1000;
		int cx=Q.front()%1000;
		int ct=Q.front()/1000000;
		Q.pop();
		if(cy==GY&&cx==GX&&ct==0) {
			cout<<D[cy][cx][ct]<<endl;
			return;
		}
		FOR(i,4) {
			int ty=cy+dy[i];
			int tx=cx+dx[i];
			int tt=to[i][ct];
			if(ty<0||ty>=H||tx<0||tx>=W||S[ty][tx]=='#') continue;
			if(D[ty][tx][tt]>D[cy][cx][ct]+1) {
				D[ty][tx][tt]=D[cy][cx][ct]+1;
				Q.push(ty*1000+tx+tt*1000000);
			}
			
			
		}
	}
	cout<<-1<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0