結果
| 問題 |
No.424 立体迷路
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-09-22 22:44:41 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,841 bytes |
| コンパイル時間 | 796 ms |
| コンパイル使用メモリ | 99,448 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-05 07:02:06 |
| 合計ジャッジ時間 | 1,536 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 21 |
ソースコード
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <unordered_set>
#include <unordered_map>
using namespace std;
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)
#define ALL(x) (x).begin(), (x).end()
int h, w;
int sx,sy,gx,gy;
int b[64][64];
bool vis[64][64];
int dy[] = {0, 1, 0, -1};
int dx[] = {1, 0, -1, 0};
bool onBoard(int x, int y, int h, int w) {
if (x < 0 || x >= h) return false;
if (y < 0 || y >= w) return false;
return true;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> h >> w;
cin >> sx >> sy >> gx >> gy;
--sx, --sy, --gx, --gy;
REP (i, h) {
string s;
cin >> s;
REP (j, w)
b[i][j] = s[j] - '0';
}
queue<pair<int, int> > Q;
Q.push({sx, sy});
vis[sx][sy] = true;
while (!Q.empty()) {
int x, y;
tie(x, y) = Q.front();
Q.pop();
REP (k, 4) {
int x2 = x + dx[k];
int y2 = y + dy[k];
if (!onBoard(x2, y2, h, w)) continue;
if (abs(b[x][y] - b[x2][y2]) > 1) continue;
if (vis[x2][y2]) continue;
Q.push({x2, y2});
vis[x2][y2] = true;
}
REP (k, 4) {
int x2 = x + dx[k];
int y2 = y + dy[k];
int x3 = x + 2 * dx[k];
int y3 = y + 2 * dy[k];
if (!onBoard(x3, y3, h, w)) continue;
if (b[x][y] != b[x3][y3] || b[x2][y2] > b[x][y]) continue;
if (vis[x3][y3]) continue;
Q.push({x3, y3});
vis[x3][y3] = true;
}
}
if (vis[gx][gy])
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}