結果
問題 | No.424 立体迷路 |
ユーザー |
![]() |
提出日時 | 2019-04-29 11:55:48 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,977 bytes |
コンパイル時間 | 675 ms |
コンパイル使用メモリ | 96,564 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-05 07:18:12 |
合計ジャッジ時間 | 1,370 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 21 |
ソースコード
#include<iostream>#include<cstdio>#include<cstring>#include <cstdlib>#include <cmath>#include<cctype>#include<string>#include<set>#include<iomanip>#include <map>#include<algorithm>#include <functional>#include<vector>#include<climits>#include<stack>#include<queue>#include <deque>#include <climits>#include <typeinfo>#include <utility>#define all(x) (x).begin(),(x).end()#define rep(i,m,n) for(int i = m;i < n;++i)#define pb push_back#define fore(i,a) for(auto &i:a)#define rrep(i,m,n) for(int i = m;i >= n;--i)#define INF INT_MAX/2using namespace std;using ll = long long;using R = double;using Data = pair<ll, vector<int>>;const ll MOD = 1e9 + 7;const ll inf = 1LL << 50;struct edge { ll from; ll to; ll cost; };int h, w;int sx, sy, gx, gy;vector<string>mp(55);int memo[55][55];int used[55][55];int check1(int x1,int y1,int x2,int y2) {int h1 = mp[y1][x1] - '0';int h2 = mp[y2][x2] - '0';if (abs(x1 - x2)+abs(y1 - y2) == 1) {if (abs(h1 - h2) <= 1)return true;}else {if (abs(x1 - x2) == 2) {int h3 = mp[y2][(x1+x2)/2] - '0';if (h1 == h2 && h1 > h3)return true;}else {int h4 = mp[(y1+y2)/2][x2] - '0';if (h1 == h2 && h1 > h4)return true;}}return false;}int dfs(int x,int y) {if (x == gx && y == gy)return true;if (memo[y][x] != -1)return memo[y][x];int dx[8] = {-1,0,1,0,-2,0,2,0};int dy[8] = {0,1,0,-1,0,2,0,-2};int ret = 0;rep(i, 0, 8) {int x_ = x + dx[i];int y_ = y + dy[i];if (0 <= y_ && y_ <= h - 1 && 0 <= x_ && x_ <= w - 1 && used[y_][x_] == 0) {if (check1(x, y, x_, y_)) {used[y_][x_] = 1;if (dfs(x_, y_))ret = 1;}}}return memo[y][x] = ret;}int main() {cin >> h >> w;cin >> sx >> sy >> gx >> gy;sx--, sy--, gx--, gy--;swap(sx, sy);swap(gx, gy);rep(i, 0, h) {cin >> mp[i];}memset(memo, -1, sizeof(memo));used[sy][sx] = 1;if (dfs(sx,sy))cout << "YES" << endl;else cout << "NO" << endl;return 0;}