結果

問題 No.424 立体迷路
ユーザー dnishdnish
提出日時 2017-07-07 07:06:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 925 bytes
コンパイル時間 1,495 ms
コンパイル使用メモリ 171,048 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-18 17:01:56
合計ジャッジ時間 2,488 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,384 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,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]&&field[nx-dx[i]][ny-dy[i]]<field[nx][ny]){
				ok[nx][ny]=true;
				q.push({nx,ny});
			}
		}
	}
	p(ok[gx][gy]?"YES":"NO");
	return 0;
}
0