結果
問題 | No.424 立体迷路 |
ユーザー |
|
提出日時 | 2016-09-22 22:32:16 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,137 bytes |
コンパイル時間 | 1,302 ms |
コンパイル使用メモリ | 167,076 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-05 06:59:22 |
合計ジャッジ時間 | 2,175 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 21 |
ソースコード
#include <bits/stdc++.h>using namespace std;int main() {int h, w;cin >> h >> w;int sy, sx, gy, gx;cin >> sy >> sx >> gy >> gx;sx--; sy--; gx--; gy--;vector<string> g(h);for (int i = 0; i < h; i++) cin >> g[i];static int dist[50][50];memset(dist, -1, sizeof(dist));dist[sy][sx] = 0;queue<pair<int, int>> q;q.emplace(sy, sx);while (!q.empty()) {int y, x;tie(y, x) = q.front(); q.pop();for (int i = 0; i < 4; i++) {int ny = y + (i - 2) % 2;int nx = x + (i - 1) % 2;if (ny < 0 || nx < 0 || ny >= h || nx >= w) continue;if (abs(g[ny][nx] - g[y][x]) <= 1 && dist[ny][nx] == -1) {dist[ny][nx] = dist[y][x] + 1;q.emplace(ny, nx);}}for (int i = 0; i < 4; i++) {int ny = y + (i - 2) % 2 * 2;int nx = x + (i - 1) % 2 * 2;if (ny < 0 || nx < 0 || ny >= h || nx >= w) continue;int nny = y + (i - 2) % 2;int nnx = x + (i - 1) % 2;if (g[nny][nnx] >= g[ny][nx]) continue;if (abs(g[ny][nx] - g[y][x]) == 0 && dist[ny][nx] == -1) {dist[ny][nx] = dist[y][x] + 1;q.emplace(ny, nx);}}}puts(dist[gy][gx] != -1 ? "YES" : "NO");}