結果

問題 No.424 立体迷路
ユーザー 夜
提出日時 2020-07-18 06:52:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,696 bytes
コンパイル時間 903 ms
コンパイル使用メモリ 97,376 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-20 16:52:13
合計ジャッジ時間 2,016 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
string s[55];
int b1[4] = { 0,0,1,-1 };
int b2[4] = { 1,-1,0,0 };
int b3[4] = { 0,0,2,-2 };
int b4[4] = { 2,-2,0,0 };
bool b[55][55] = { false };
int main() {
	int h, w;
	cin >> h >> w;
	int sx, sy, gx, gy;
	cin >> sx >> sy >> gx >> gy;
	sx--; sy--; gx--; gy--;
	for (int i = 0; i < h; i++) {
		cin >> s[i];
	}
	queue<pair<int, int>> que;
	que.push(make_pair(sx, sy));
	b[sx][sy] = true;
	while (!que.empty()) {
		int x = que.front().first;
		int y = que.front().second;
		if (x == gx && y == gy) {
			cout << "YES" << endl;
			return 0;
		}
		for (int i = 0; i < 4; i++) {
			if (x + b1[i] < 0 || x + b1[i] >= h || y + b2[i] < 0 || y + b2[i] >= w) {
				continue;
			}
			if (abs(int(s[x][y] - s[x + b1[i]][y + b2[i]])) <= 1) {
				if (!b[x + b1[i]][y + b2[i]]) {
					b[x + b1[i]][y + b2[i]] = true;
					que.push(make_pair(x + b1[i], y + b2[i]));
				}
			}
		}
		for (int j = 0; j < 4; j++) {
			if(x + b3[j] < 0 || x + b3[j] >= h || y + b4[j] < 0 || y + b4[j] >= w) {
				continue;
			}
			if(s[x][y] == s[x + b3[j]][y + b4[j]]) {
				if(s[x][y] > s[x + b1[j]][y + b2[j]]) {
				   if(!b[x + b3[j]][y + b4[j]]) {
						b[x + b3[j]][y + b4[j]] = true;
						que.push(make_pair(x + b3[j], y + b4[j]));
					}
				}
			}
		}
		if (x == gx && y == gy) {
			cout << "YES" << endl;
			return 0;
		}
		que.pop();
	}
	cout << "NO" << endl;
	return 0;
}
0