結果

問題 No.424 立体迷路
ユーザー dnishdnish
提出日時 2017-07-07 07:01:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 884 bytes
コンパイル時間 1,852 ms
コンパイル使用メモリ 171,176 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-15 22:54:47
合計ジャッジ時間 2,639 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=(n);i<(int) N;i++)
#define p(s) cout<<(s)<<endl
#define CK(n,a,b) ((a)<=(n)&&(n)<(b))
#define F first
#define S second
using namespace std;

bool ok[55][55];
string field[55];
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int main() {
	int h,w;
	int sx,sy,gx,gy;
	cin>>h>>w>>sx>>sy>>gx>>gy;
	REP(i,0,h) cin>>field[i];
	sy--;sx--;gy--;gx--;
	ok[sx][sy]=true;
	queue<pair<int,int>> q;
	q.push({sx,sy});
	while(!q.empty()){
		auto now=q.front();q.pop();
		REP(i,0,4){
			int nx=now.F+dx[i],ny=now.S+dy[i];
			if(!ok[nx][ny]&&CK(nx,0,h)&&CK(ny,0,w)&&abs(field[now.F][now.S]-field[nx][ny])<=1){
				ok[nx][ny]=true;
				q.push({nx,ny});
			}
			ny+=dy[i];nx+=dx[i];
			if(!ok[nx][ny]&&CK(nx,0,h)&&CK(ny,0,w)&&field[nx][ny]==field[now.F][now.S]){
				ok[nx][ny]=true;
				q.push({nx,ny});
			}
		}
	}
	p(ok[gx][gy]?"YES":"NO");
	return 0;
}
0