結果
問題 | No.424 立体迷路 |
ユーザー |
![]() |
提出日時 | 2016-09-22 22:57:54 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 1,580 bytes |
コンパイル時間 | 710 ms |
コンパイル使用メモリ | 80,980 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-05 07:05:08 |
合計ジャッジ時間 | 1,489 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 21 |
ソースコード
#include<iostream>#include<vector>#include<string>#include<algorithm>#include<queue>bool inside(int h, int w, int x, int y) {if (x < 0 || y < 0 || x >= h || y >= w) return false;return true;}int main() {int h, w, sx, sy, gx, gy;std::cin >> h >> w;std::cin >> sx >> sy >> gx >> gy;sx--;sy--;gx--;gy--;std::vector<std::string> d(h);for (int i = 0; i < h; i++) {std::cin >> d[i];}std::queue<std::pair<int, int> > p;p.push({ sx, sy });int visited[50][50] = { 0 };int dictx[] = { 1,0,-1,0 }, dicty[] = { 0,1,0,-1 };while (!p.empty()) {int x, y;auto j = p.front(); p.pop();x = j.first;y = j.second;if (visited[x][y]) continue;//std::cout << x << " " << y << std::endl;visited[x][y] = 1;for (int i = 0; i < 4; i++) {if (inside(h, w, x + dictx[i], y + dicty[i])) {// 同じ高さif (d[x][y] == d[x + dictx[i]][y + dicty[i]]) {p.push({ x + dictx[i],y + dicty[i] });}// 登るif (d[x][y] + 1 == d[x + dictx[i]][y + dicty[i]]) {p.push({ x + dictx[i],y + dicty[i] });}// 降りるif (d[x][y] - 1 == d[x + dictx[i]][y + dicty[i]]) {p.push({ x + dictx[i],y + dicty[i] });}// 1つ飛びif (inside(h, w, x + dictx[i] * 2, y + dicty[i] * 2)) {if (d[x + dictx[i]][y + dicty[i]] < d[x][y] && d[x][y] == d[x + dictx[i] * 2][y + dicty[i] * 2]) {p.push({ x + dictx[i] * 2,y + dicty[i] * 2});}}}}}if (visited[gx][gy] == 1) {std::cout << "YES" << std::endl;} else {std::cout << "NO" << std::endl;}return 0;}