結果
問題 | No.424 立体迷路 |
ユーザー |
![]() |
提出日時 | 2018-10-30 00:27:17 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,701 bytes |
コンパイル時間 | 1,788 ms |
コンパイル使用メモリ | 204,772 KB |
最終ジャッジ日時 | 2025-01-06 15:05:04 |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 21 |
ソースコード
#include <bits/stdc++.h>using namespace std;using i64 = int64_t;using vi = vector<i64>;using vvi = vector<vi>;int main() {int h, w;cin >> h >> w;int sx, sy, gx, gy;cin >> sx >> sy >> gx >> gy;sx--;sy--;gx--;gy--;vvi b(h, vi(w));for (int i = 0; i < h; i++) {for (int j = 0; j < w; j++) {char c;cin >> c;b[i][j] = c - '0';}}vvi dist(h, vi(w, 1e9));dist[sx][sy] = 0;using ii = pair<int, int>;queue<ii> que;que.push(ii(sx, sy));auto ok = [&](int x, int y) {return 0 <= x && x < h && 0 <= y && y < w;};int dx[] = {-1, 1, 0, 0};int dy[] = {0, 0, -1, 1};while (que.size()) {ii t = que.front();que.pop();for (int i = 0; i < 4; i++) {for (int j = 1; j <= 2; j++) {int x = t.first + dx[i] * j;int y = t.second + dy[i] * j;if (ok(x, y)) {if (j == 2) {if (b[t.first][t.second] != b[x][y]) continue;if (!(b[t.first + dx[i]][t.second + dy[i]] < b[t.first][t.second])) continue;} else {if (abs(b[t.first][t.second] - b[x][y]) > 1) continue;}if (dist[t.first][t.second] + 1 < dist[x][y]) {dist[x][y] = dist[t.first][t.second] + 1;que.push(ii(x, y));}}}}}if (dist[gx][gy] != 1e9) {cout << "YES" << endl;} else {cout << "NO" << endl;}}