結果
問題 |
No.424 立体迷路
|
ユーザー |
![]() |
提出日時 | 2018-03-04 17:11:54 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,696 bytes |
コンパイル時間 | 1,066 ms |
コンパイル使用メモリ | 98,764 KB |
実行使用メモリ | 6,940 KB |
最終ジャッジ日時 | 2024-07-05 07:15:14 |
合計ジャッジ時間 | 1,819 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 21 |
ソースコード
#include <iostream> #include <vector> #include <string> #include <cstring> #include <math.h> #include <cmath> #include <limits.h> #include <map> #include <set> #include <queue> #include <algorithm> #include <functional> #include <stdio.h> using namespace std; long long MOD = 1000000007; int H,W; vector<string> V; vector< vector<int> > D; struct Point { Point(){}; Point( int a, int b ){ x = a; y = b; }; int x; int y; }; Point S, G; int dir[4][2] = { {1,0}, {0,1}, {-1,0}, {0,-1} }; bool isOK( int x, int y ) { return x >= 0 && y >= 0 && x < W && y < H; } bool func( Point p ) { // cout << p.x << " " << p.y << endl; if ( p.x == G.x && p.y == G.y ) { return true; } D[p.y][p.x] = 1; Point np; for ( int i = 0; i < 4; i++ ) { int nx1 = p.x + dir[i][0]; int ny1 = p.y + dir[i][1]; np.x = nx1; np.y = ny1; if (isOK(nx1,ny1) && D[ny1][nx1] == 0 && ( abs( V[p.y][p.x]-V[ny1][nx1] ) <= 1 ) && func( np ) ) { return true; } int nx2 = p.x + dir[i][0]*2; int ny2 = p.y + dir[i][1]*2; np.x = nx2; np.y = ny2; if ( isOK(nx2,ny2) && D[ny2][nx2] == 0 && V[p.y][p.x] == V[ny2][nx2] && V[p.y][p.x] > V[ny1][nx1] && func( np ) ) { return true; } } return false; } int main() { cin >> H >> W; int sx,sy,gx,gy; cin >> sy >> sx >> gy >> gx; sx--; sy--; gx--; gy--; S.x = sx; S.y = sy; G.x = gx; G.y = gy; V.resize(H); D.resize(H); for ( int i = 0; i < H; i++ ) { cin >> V[i]; D[i].resize(W,0); } cout << ( func( S ) ? "YES" : "NO" ) << endl; return 0; }