結果
問題 | No.424 立体迷路 |
ユーザー |
![]() |
提出日時 | 2019-02-01 20:05:54 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 1,200 bytes |
コンパイル時間 | 1,500 ms |
コンパイル使用メモリ | 167,508 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-05 07:17:56 |
合計ジャッジ時間 | 2,526 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 21 |
ソースコード
#include <bits/stdc++.h>using namespace std;int h, w, sx, sy, gx, gy;const int MAX = 55;int B[MAX][MAX];int dx[4] = {-1, 1, 0, 0};int dy[4] = {0, 0, -1, 1};bool seen[MAX][MAX];void dfs(int x, int y){seen[x][y] = true;for(int i = 0; i < 2; i++){for(int j = 0; j < 4; j++){int nx, ny;nx = x + dx[j] * (i + 1);ny = y + dy[j] * (i + 1);if(nx < 0 or nx >= h or ny < 0 or ny >= w) continue;if(seen[nx][ny]) continue;if(i == 0){if(abs(B[x][y] - B[nx][ny]) > 1) continue;}else{int bet = B[(x + nx) / 2][(y + ny) / 2];if(B[x][y] != B[nx][ny] or B[x][y] < bet) continue;}dfs(nx, ny);}}}int main(){cin.tie(0);ios::sync_with_stdio(false);cin >> h >> w;cin >> sx >> sy >> gx >> gy;sx--; sy--; gx--; gy--;for(int i = 0; i < h; i++){string s;cin >> s;for(int j = 0; j < w; j++){B[i][j] = s[j] - '0';}}dfs(sx, sy);if(seen[gx][gy]) cout << "YES" << endl;else cout << "NO" << endl;return 0;}