結果
問題 | No.424 立体迷路 |
ユーザー |
![]() |
提出日時 | 2016-09-22 23:23:20 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,488 bytes |
コンパイル時間 | 1,099 ms |
コンパイル使用メモリ | 159,504 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-05 07:06:12 |
合計ジャッジ時間 | 1,768 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 21 |
ソースコード
#include <bits/stdc++.h>#define rep(x, to) for (int x = 0; x < (to); x++)#define REP(x, a, to) for (int x = (a); x < (to); x++)#define EPS (1e-14)#define _PA(x,N) rep(i,N){cout<<x[i]<<" ";}cout<<endl;#define _PA2(x,H,W) rep(i,(H)){rep(j,(W)){cout<<x[i][j]<<" ";}cout<<endl;}using namespace std;typedef long long ll;typedef pair<int, int> PII;typedef pair<ll, ll> PLL;typedef complex<double> Complex;typedef vector< vector<int> > Mat;int dx[] = {1, 0, -1, 0};int dy[] = {0, 1, 0, -1};int h, w;int sx, sy, gx, gy;string b[55];int f[55][55];char visit[55][55];void dfs(int y, int x) {if (visit[y][x]) return;visit[y][x] = 1;for (int i = 0; i < 4; i++) {int ny = y + dy[i];int nx = x + dx[i];if (ny < 0 || ny >= h) continue;if (nx < 0 || nx >= w) continue;if (f[ny][nx] - 1 <= f[y][x] && f[y][x] <= f[ny][nx] + 1) {dfs(ny, nx);} else if (f[y][x] - f[ny][nx] >= 2) {ny += dy[i];nx += dx[i];if (ny < 0 || ny >= h) continue;if (nx < 0 || nx >= w) continue;if (f[ny][nx] != f[y][x]) continue;dfs(ny, nx);}}}void solve() {dfs(sy, sx);if (visit[gy][gx]) {cout << "YES" << endl;} else {cout << "NO" << endl;}}int main() {cin >> h >> w;cin >> sx >> sy >> gx >> gy;sx--, sy--, gx--, gy--;swap(sy, sx);swap(gy ,gx);for (int i = 0; i < h; i++) {cin >> b[i];}for (int i = 0; i < h; i++) {for (int j = 0; j < w; j++) {f[i][j] = b[i][j] - '0';}}solve();return 0;}