結果

問題 No.424 立体迷路
ユーザー 👑 kmjpkmjp
提出日時 2016-09-22 22:25:15
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 1,625 bytes
コンパイル時間 1,497 ms
コンパイル使用メモリ 153,656 KB
実行使用メモリ 7,100 KB
最終ジャッジ日時 2023-09-18 16:41:37
合計ジャッジ時間 2,780 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
7,044 KB
testcase_01 AC 7 ms
6,996 KB
testcase_02 AC 7 ms
6,924 KB
testcase_03 AC 7 ms
6,876 KB
testcase_04 AC 7 ms
6,808 KB
testcase_05 AC 7 ms
7,064 KB
testcase_06 AC 7 ms
6,884 KB
testcase_07 AC 7 ms
6,824 KB
testcase_08 AC 7 ms
6,944 KB
testcase_09 AC 7 ms
7,016 KB
testcase_10 AC 6 ms
6,840 KB
testcase_11 AC 7 ms
6,884 KB
testcase_12 AC 7 ms
7,100 KB
testcase_13 AC 7 ms
7,060 KB
testcase_14 AC 7 ms
7,036 KB
testcase_15 AC 7 ms
6,952 KB
testcase_16 AC 7 ms
6,928 KB
testcase_17 AC 7 ms
7,072 KB
testcase_18 AC 7 ms
7,100 KB
testcase_19 AC 7 ms
6,880 KB
testcase_20 AC 7 ms
7,016 KB
testcase_21 AC 7 ms
6,952 KB
testcase_22 AC 7 ms
6,992 KB
testcase_23 AC 7 ms
6,876 KB
testcase_24 AC 7 ms
6,832 KB
testcase_25 AC 7 ms
6,812 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#undef _P
#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 ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

template<int um> class UF {
	public:
	vector<int> par,rank;
	UF() {rank=vector<int>(um,0); for(int i=0;i<um;i++) par.push_back(i);}
	int operator[](int x) {return (par[x]==x)?(x):(par[x] = operator[](par[x]));}
	int operator()(int x,int y) {
		if((x=operator[](x))==(y=operator[](y))) return x;
		if(rank[x]>rank[y]) return par[x]=y;
		rank[x]+=rank[x]==rank[y]; return par[y]=x;
	}
};
UF<500000> uf;


int H,W;
int SX,SY,GX,GY;
string S[51];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>W;
	cin>>SX>>SY>>GX>>GY;
	FOR(y,H) cin>>S[y];
	
	FOR(y,H) {
		FOR(x,W-1) if(abs(S[y][x]-S[y][x+1])<=1) uf(y*50+x,y*50+x+1);
		FOR(x,W-2) if(S[y][x]==S[y][x+2]&&S[y][x+1]<S[y][x]) uf(y*50+x,y*50+x+2);
	}
	FOR(x,W) {
		FOR(y,H-1) if(abs(S[y][x]-S[y+1][x])<=1) uf(y*50+x,y*50+x+50);
		FOR(y,H-2) if(S[y][x]==S[y+2][x]&&S[y+1][x]<S[y][x]) uf(y*50+x,y*50+x+100);
	}
	
	
	
	if(uf[(SX-1)*50+(SY-1)]==uf[(GX-1)*50+(GY-1)]) cout<<"YES"<<endl;
	else cout<<"NO"<<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);
	solve(); return 0;
}
0