結果

問題 No.2096 Rage With Our Friends
ユーザー 👑 kmjpkmjp
提出日時 2022-10-09 00:44:11
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 210 ms / 5,000 ms
コード長 1,840 bytes
コンパイル時間 2,305 ms
コンパイル使用メモリ 205,528 KB
実行使用メモリ 39,228 KB
最終ジャッジ日時 2023-09-05 05:41:16
合計ジャッジ時間 5,586 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,528 KB
testcase_01 AC 2 ms
5,516 KB
testcase_02 AC 2 ms
5,512 KB
testcase_03 AC 2 ms
5,708 KB
testcase_04 AC 2 ms
5,468 KB
testcase_05 AC 2 ms
5,544 KB
testcase_06 AC 2 ms
5,484 KB
testcase_07 AC 2 ms
5,680 KB
testcase_08 AC 2 ms
5,584 KB
testcase_09 AC 2 ms
5,552 KB
testcase_10 AC 2 ms
5,588 KB
testcase_11 AC 122 ms
38,956 KB
testcase_12 AC 119 ms
39,164 KB
testcase_13 AC 153 ms
39,228 KB
testcase_14 AC 190 ms
39,004 KB
testcase_15 AC 124 ms
38,952 KB
testcase_16 AC 2 ms
5,592 KB
testcase_17 AC 153 ms
39,124 KB
testcase_18 AC 2 ms
5,728 KB
testcase_19 AC 2 ms
5,720 KB
testcase_20 AC 2 ms
5,664 KB
testcase_21 AC 207 ms
39,168 KB
testcase_22 AC 210 ms
39,108 KB
testcase_23 AC 15 ms
27,348 KB
testcase_24 AC 132 ms
30,696 KB
testcase_25 AC 78 ms
35,352 KB
testcase_26 AC 46 ms
34,668 KB
testcase_27 AC 31 ms
16,644 KB
testcase_28 AC 4 ms
10,624 KB
testcase_29 AC 16 ms
14,076 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,SX,GX,SY,GY;
string S[2010];
int U[2010][2010];
int D[2010][2010];
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>W>>SY>>SX>>GY>>GX;
	SY--,GY--;
	SX--,GX--;
	FOR(y,H) cin>>S[y];
	S[H]=string(W,'#');
	H++;
	FOR(x,W) {
		FOR(y,H) {
			D[y][x]=1<<30;
			if(y) U[y][x]=U[y-1][x];
			else U[y][x]=-1;
			if(S[y][x]=='.') U[y][x]=y;
		}
	}
	deque<int> Q;
	D[SY][SX]=0;
	Q.push_back(SY*2000+SX);
	while(Q.size()) {
		int cy=Q.front()/2000;
		int cx=Q.front()%2000;
		Q.pop_front();
		int co=D[cy][cx];
		if(cy==GY&&cx==GX) {
			cout<<co<<endl;
			return;
		}
		
		for(int tx=cx-1;tx<=cx+1;tx+=2) if(tx>=0&&tx<W) {
			y=U[cy+1][tx];
			if(y<0) continue;
			if(chmin(D[y][tx],co)) Q.push_front(y*2000+tx);
			if(y<cy) {
				int hy=cy+1;
				int sy=y+(cy-y)/2+1;
				for(int tx2=tx-1;tx2<=tx+1;tx2+=2) if(tx2>=0&&tx2<W) {
					int ny=U[hy][tx2];
					if(ny>=0&&chmin(D[ny][tx2],co+1)) Q.push_back(ny*2000+tx2);
					ny=U[sy][tx2];
					if(ny>=0&&chmin(D[ny][tx2],co)) Q.push_front(ny*2000+tx2);
				}
			}
		}
	}
	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