結果

問題 No.424 立体迷路
ユーザー ふーらくたるふーらくたる
提出日時 2016-09-22 22:49:36
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,556 bytes
コンパイル時間 642 ms
コンパイル使用メモリ 66,660 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-05 07:02:55
合計ジャッジ時間 1,479 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <iostream>
#include <queue>
#include <utility>
using namespace std;
using P = pair<int, int>;
const int MAX_H = 60;
const int MAX_W = 60;
int dx[4] = {1, 0, -1, 0},
dy[4] = {0, 1, 0, -1};
string b[MAX_H];
bool visited[MAX_H][MAX_W];
int h, w, sx, sy, gx, gy;
bool inside(int x, int y) {
return 0 <= x && x < h && 0 <= y && y < w;
}
int main() {
cin >> h >> w;
cin >> sx >> sy >> gx >> gy;
sx--; sy--;
gx--; gy--;
for (int i = 0; i < h; i++) {
cin >> b[i];
}
queue<P> que;
que.push(P(sx, sy));
visited[sx][sy] = true;
while (!que.empty()) {
P p = que.front(); que.pop();
if (p.first == gx && p.second == gy) {
cout << "YES" << endl;
return 0;
}
int x = p.first,
y = p.second;
for (int i = 0; i < 4; i++) {
for (int d = 1; d <= 2; d++) {
int nx = x + dx[i] * d,
ny = y + dy[i] * d;
if (!inside(nx, ny) || visited[nx][ny]) continue;
if (d == 1 && abs((b[x][y] - '0') - (b[nx][ny] - '0')) <= 1) {
que.push(P(nx, ny));
visited[nx][ny] = true;
}
if (d == 2 && abs((b[x][y] - '0') - (b[nx][ny] - '0')) == 0
&& b[x][y] - '0' > b[x + dx[i]][y + dy[i]] - '0') {
que.push(P(nx, ny));
visited[nx][ny] = true;
}
}
}
}
cout << "NO" << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0