結果
| 問題 |
No.424 立体迷路
|
| コンテスト | |
| ユーザー |
Ai3Shota
|
| 提出日時 | 2018-06-26 08:12:30 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,275 bytes |
| コンパイル時間 | 1,091 ms |
| コンパイル使用メモリ | 160,244 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-05 07:16:16 |
| 合計ジャッジ時間 | 1,800 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 21 |
ソースコード
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int H, W, Sx, Sy, Gx, Gy;
vector<string> B(51);
bool dp[51][51] = {{0}};
void rec(int x = Sx - 1, int y = Sy - 1, int high = B[Sy - 1][Sx - 1] - '0'){
if(x <= -1 || x >= W || y <= -1 || y >= H) return;
if(high != B[y][x] - '0') return;
if(x == Gx - 1 && y == Gy- 1){
cout << "YES" << endl;
exit(0);
}
if(dp[y][x]) return;
dp[y][x] = true;
rec(x - 1, y, high);
rec(x + 1, y, high);
rec(x, y - 1, high);
rec(x, y + 1, high);
rec(x - 1, y, high + 1);
rec(x + 1, y, high + 1);
rec(x, y - 1, high + 1);
rec(x, y + 1, high + 1);
rec(x - 1, y, high - 1);
rec(x + 1, y, high - 1);
rec(x, y - 1, high - 1);
rec(x, y + 1, high - 1);
if(x - 1 >= 0 && high > B[y][x - 1] - '0') rec(x - 2, y, high);
if(x + 1 >= 0 && high > B[y][x + 1] - '0') rec(x + 2, y, high);
if(y - 1 >= 0 && high > B[y - 1][x] - '0') rec(x, y - 2, high);
if(y + 1 >= 0 && high > B[y + 1][x] - '0') rec(x, y + 2, high);
return;
}
int main(void){
cin >> H >> W >> Sy >> Sx >> Gy >> Gx;
for(int i = 0; i < H; ++i) cin >> B[i];
rec();
cout << "NO" << endl;
return 0;
}
Ai3Shota