結果
| 問題 |
No.424 立体迷路
|
| コンテスト | |
| ユーザー |
nak3
|
| 提出日時 | 2017-03-26 14:16:48 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,541 bytes |
| コンパイル時間 | 1,429 ms |
| コンパイル使用メモリ | 166,336 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-06 06:28:09 |
| 合計ジャッジ時間 | 1,889 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 WA * 1 |
| other | AC * 21 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define INF 2000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;
int main()
{
int h, w;
cin >> h >> w;
int sx, sy, gx, gy;
cin >> sx >> sy >> gx >> gy;
string b[h+1];
for (int i = 1; i <= h; i++) {
cin >> b[i];
}
bool rec[h+1][w+1];
for (int i = 0; i <= h; i++) {
for (int j = 0; j <= w; j++) {
rec[i][j] = false;
}
}
// start
queue<P> q;
q.push(P(sx,sy));
while (true) {
if (q.empty()) {
cout << "NO" << "\n";
return 0;
}
P tmp = q.front(); q.pop();
int x = tmp.first;
int y = tmp.second;
if (x==gx&&y==gy) {
cout << "YES" << "\n";
return 0;
}
// cout << "debug " << x << " " << y << "\n";
if (rec[x][y]) {
continue;
}
if (x-1>=1&&abs((b[x][y-1]-'0')-(b[x-1][y-1]-'0'))<=1) {
q.push(P(x-1,y));
}
if (y-1>=1&&abs((b[x][y-1]-'0')-(b[x][y-1-1]-'0'))<=1) {
q.push(P(x,y-1));
}
if (x+1<=h&&abs((b[x][y-1]-'0')-(b[x+1][y-1]-'0'))<=1) {
q.push(P(x+1,y));
}
if (y+1<=w&&abs((b[x][y-1]-'0')-(b[x][y+1-1]-'0'))<=1) {
q.push(P(x,y+1));
}
if (x-2>=1&&(b[x][y-1]==b[x-2][y-1])&&(b[x-1][y-1]-'0')<=(b[x-2][y-1]-'0')) {
q.push(P(x-2,y));
}
if (y-2>=1&&(b[x][y-1]==b[x][y-2-1])&&(b[x][y-1-1]-'0')<=(b[x][y-2-1]-'0')) {
q.push(P(x,y-2));
}
if (x+2<=h&&(b[x][y-1]==b[x+2][y-1])&&(b[x+1][y]-'0')<=(b[x][y-1]-'0')) {
q.push(P(x+2,y));
}
if (y+2<=w&&(b[x][y-1]==b[x][y+2-1])&&(b[x][y+1-1]-'0')<=(b[x][y+2-1]-'0')) {
q.push(P(x,y+2));
}
rec[x][y] = true;
}
}
nak3