結果
問題 | No.424 立体迷路 |
ユーザー |
![]() |
提出日時 | 2017-02-01 14:00:32 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 2,220 bytes |
コンパイル時間 | 744 ms |
コンパイル使用メモリ | 79,980 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-05 07:13:20 |
合計ジャッジ時間 | 1,231 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 21 |
ソースコード
#include <algorithm>#include <cstdio>#include <iostream>#include <map>#include <math.h>#include <queue>#include <set>#include <sstream>#include <stack>#include <string>#include <string.h>#include <vector>using namespace std;#define ll long long#define INF (1 << 30)#define INFLL (1LL << 60)#define FOR(i,a,b) for(ll i = (a);i<(b);i++)#define REP(i,a) FOR(i,0,(a))#define MP make_pairint h, w;int sx, sy, gx, gy;int hyo[51][51] = {};int DIRX[4] = {1, -1, 0, 0};int DIRY[4] = {0, 0, 1, -1};int DIRX2[4] = {2, -2, 0, 0};int DIRY2[4] = {0, 0, 2, -2};bool check(int nowx, int nowy){if(nowx < 0 || nowy < 0 || nowy >= h || nowx >= w) return true;return false;}bool solve(){queue<pair<int, int> > que;que.push(MP(sx, sy));bool used[51][51] = {};while(que.size()){pair<int, int> data = que.front();que.pop();int nowx = data.first;int nowy = data.second;if(used[nowx][nowy]) continue;used[nowx][nowy] = true;// cout << nowx << "," << nowy << endl;if(nowx == gx && nowy == gy){return true;}for(int i = 0;i < 4;i++){int tox = nowx + DIRX[i], toy = nowy + DIRY[i];if(check(tox, toy)) continue;if(abs(hyo[nowx][nowy] - hyo[tox][toy]) > 1) continue;// if(nowx == sx && nowy == sy){// cout << tox << "," << toy << "-" << hyo[nowx][nowy] << endl;// }que.push(MP(tox, toy));}for(int i = 0;i < 4;i++){int tox = nowx + DIRX2[i], toy = nowy + DIRY2[i];int midx = nowx + DIRX[i], midy = nowy + DIRY[i];if(check(tox, toy)) continue;if(hyo[nowx][nowy] != hyo[tox][toy]) continue;if(hyo[midx][midy] > hyo[tox][toy]) continue;que.push(MP(tox, toy));}}return false;}int main() {cin >> h >> w;cin >> sy >> sx >> gy >> gx;sx--;gx--;sy--;gy--;string str;for(int i = 0;i < h;i++){cin >> str;for(int j = 0;j < str.size();j++){hyo[j][i] = str[j] - '0';}}// cout << sx << "--" << sy << endl;// cout << hyo[1][3] << endl;// cout << "--------------" << endl;// for(int i = 0;i < h;i++){// for(int j = 0;j < w;j++){// cout << hyo[j][i];// }// cout << endl;// }bool ans = solve();if(ans) cout << "YES" << endl;else cout << "NO" << endl;return 0;}