結果

問題 No.424 立体迷路
ユーザー furafura
提出日時 2020-05-15 01:04:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,074 bytes
コンパイル時間 2,072 ms
コンパイル使用メモリ 207,220 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-14 12:02:35
合計ジャッジ時間 3,352 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

using graph=vector<vector<int>>;

void add_edge(graph& G,int u,int v){
	G[u].emplace_back(v);
	G[v].emplace_back(u);
}

vector<int> distance(const graph& G,int s){
	const int INF=INT_MAX;
	int n=G.size();
	vector<int> d(n,INF);
	d[s]=0;
	queue<int> Q; Q.emplace(s);
	while(!Q.empty()){
		int u=Q.front(); Q.pop();
		for(int v:G[u]) if(d[v]==INF) {
			d[v]=d[u]+1;
			Q.emplace(v);
		}
	}
	return d;
}

int main(){
	int h,w; scanf("%d%d",&h,&w);
	int sx,sy,gx,gy; scanf("%d%d%d%d",&sy,&sx,&gy,&gx); sx--; sy--; gx--; gy--;
	char B[50][51];
	rep(i,h) scanf("%s",B[i]);

	graph G(h*w);
	rep(i,h) rep(j,w) {
		if(i<h-1 && abs(B[i][j]-B[i+1][j])<=1) add_edge(G,i*w+j,(i+1)*w+j);
		if(j<w-1 && abs(B[i][j]-B[i][j+1])<=1) add_edge(G,i*w+j,i*w+(j+1));
		if(i<h-2 && B[i][j]==B[i+2][j] && B[i][j]>B[i+1][j]) add_edge(G,i*w+j,(i+2)*w+j);
		if(j<w-2 && B[i][j]==B[i][j+2] && B[i][j]>B[i][j+1]) add_edge(G,i*w+j,i*w+(j+2));
	}
	puts(distance(G,sy*w+sx)[gy*w+gx]<INT_MAX?"YES":"NO");

	return 0;
}
0