結果

問題 No.2096 Rage With Our Friends
ユーザー 👑 kmjpkmjp
提出日時 2022-10-09 00:43:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,840 bytes
コンパイル時間 2,495 ms
コンパイル使用メモリ 205,520 KB
実行使用メモリ 10,724 KB
最終ジャッジ日時 2023-09-05 05:40:12
合計ジャッジ時間 7,353 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,544 KB
testcase_01 AC 2 ms
5,480 KB
testcase_02 AC 2 ms
5,700 KB
testcase_03 AC 2 ms
5,528 KB
testcase_04 AC 2 ms
5,504 KB
testcase_05 AC 2 ms
5,500 KB
testcase_06 AC 2 ms
5,548 KB
testcase_07 AC 2 ms
5,532 KB
testcase_08 AC 2 ms
5,544 KB
testcase_09 AC 2 ms
5,744 KB
testcase_10 AC 2 ms
5,576 KB
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 AC 3 ms
5,696 KB
testcase_17 RE -
testcase_18 AC 2 ms
5,580 KB
testcase_19 AC 2 ms
5,892 KB
testcase_20 AC 3 ms
7,696 KB
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 WA -
testcase_28 AC 3 ms
8,664 KB
testcase_29 AC 16 ms
9,744 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[1010];
int U[1010][1010];
int D[1010][1010];
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*1000+SX);
	while(Q.size()) {
		int cy=Q.front()/1000;
		int cx=Q.front()%1000;
		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*1000+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*1000+tx2);
					ny=U[sy][tx2];
					if(ny>=0&&chmin(D[ny][tx2],co)) Q.push_front(ny*1000+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