結果
| 問題 |
No.424 立体迷路
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-05-30 23:19:32 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 1,421 bytes |
| コンパイル時間 | 1,884 ms |
| コンパイル使用メモリ | 180,184 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-08 18:31:35 |
| 合計ジャッジ時間 | 2,836 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 21 |
ソースコード
#include <bits/stdc++.h>
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()
const double PI = acos(-1);
int dy[] = {0, 1, 0, -1};
int dx[] = {1, 0, -1, 0};
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int h, w;
cin >> h >> w;
int sx, sy, gx, gy;
cin >> sx >> sy >> gx >> gy;
--sx, --sy, --gx, --gy;
vector<string> bd(h);
REP(i, h)
cin >> bd[i];
queue<pair<int, int> > q;
vector<vector<bool> > vis(h, vector<bool>(w));
vis[sx][sy] = true;
q.emplace(sx, sy);
while (!q.empty()) {
int x, y;
tie(x, y) = q.front();
q.pop();
// neighbor
REP (k, 4) {
int xt = x + dx[k];
int yt = y + dy[k];
if (xt < 0 || xt >= h) continue;
if (yt < 0 || yt >= w) continue;
if (abs(bd[x][y] - bd[xt][yt]) < 2 && !vis[xt][yt]) {
vis[xt][yt] = true;
q.emplace(xt, yt);
}
}
// jump
REP(k, 4) {
int xt = x + 2 * dx[k];
int yt = y + 2 * dy[k];
if (xt < 0 || xt >= h) continue;
if (yt < 0 || yt >= w) continue;
if (bd[x][y] == bd[xt][yt] && bd[x][y] > bd[x+dx[k]][y+dy[k]] && !vis[xt][yt]) {
vis[xt][yt] = true;
q.emplace(xt, yt);
}
}
}
if (vis[gx][gy])
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}