結果
| 問題 |
No.424 立体迷路
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-09-22 22:31:05 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,034 bytes |
| コンパイル時間 | 1,594 ms |
| コンパイル使用メモリ | 166,744 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-17 13:40:46 |
| 合計ジャッジ時間 | 2,545 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 19 WA * 2 |
ソースコード
#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;
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");
}