結果

問題 No.424 立体迷路
ユーザー kyo1kyo1
提出日時 2020-09-05 12:32:32
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 1,439 bytes
コンパイル時間 2,412 ms
コンパイル使用メモリ 209,704 KB
最終ジャッジ日時 2025-01-14 07:04:47
ジャッジサーバーID
(参考情報)
judge2 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

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

#include <bits/stdc++.h>
using namespace std;
const std::vector<int> dx = {1, -1, 0, 0}, dy = {0, 0, 1, -1};
template <typename T>
bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int H, W;
cin >> H >> W;
int sy, sx, gy, gx;
cin >> sy >> sx >> gy >> gx;
sy--, sx--, gy--, gx--;
vector<vector<int>> G(H, vector<int>(W));
for (int i = 0; i < H; i++) {
string s;
cin >> s;
for (int j = 0; j < W; j++) {
G[i][j] = s[j] - '0';
}
}
vector<vector<bool>> used(H, vector<bool>(W, false));
used[sy][sx] = true;
queue<pair<int, int>> que;
que.push(make_pair(sy, sx));
while (!que.empty()) {
auto [y, x] = que.front();
que.pop();
for (int i = 0; i < 4; i++) {
int ny = y + dy[i], nx = x + dx[i];
if (ny < 0 || ny >= H || nx < 0 || nx >= W) continue;
if (abs(G[y][x] - G[ny][nx]) <= 1 && !used[ny][nx]) {
used[ny][nx] = true;
que.push(make_pair(ny, nx));
}
int nny = ny + dy[i], nnx = nx + dx[i];
if (nny < 0 || nny >= H || nnx < 0 || nnx >= W) continue;
if (G[nny][nnx] == G[y][x] && G[y][x] > G[ny][nx] && !used[nny][nnx]) {
used[nny][nnx] = true;
que.push(make_pair(nny, nnx));
}
}
}
if (used[gy][gx]) {
cout << "YES" << '\n';
} else {
cout << "NO" << '\n';
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0