結果
問題 | No.424 立体迷路 |
ユーザー |
![]() |
提出日時 | 2017-07-03 14:03:53 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,947 bytes |
コンパイル時間 | 875 ms |
コンパイル使用メモリ | 98,476 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-05 07:14:26 |
合計ジャッジ時間 | 1,403 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 21 |
ソースコード
#define ll long long#define ffor(i, a, b) for (int i = (a); i < (b); i++)#define rfor(i, a, b) for (int i = (b)-1; i >= (a); i--)#define rep(i, n) for (int i = 0; i < (n); i++)#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)#include <algorithm>#include <cmath>#include <cstdio>#include <iomanip>#include <iostream>#include <map>#include <queue>#include <set>#include <stack>#include <string>#include <vector>#define SIZE 100001#define MOD 1000000007#define INF 100000000using namespace std;int h, w, sx, sy, gx, gy;string b[51];int visited[51][51];int dx[4] = {1, 0, -1, 0};int dy[4] = {0, 1, 0, -1};typedef pair<int, int> P;bool bfs() {rep(i, h) rep(j, w) visited[i][j] = 0;queue<P> que;sx--;sy--;gx--;gy--;que.push(P(sy, sx));visited[sx][sy] = 1;int flag = 1;while (!que.empty()) {P p = que.front();que.pop();if (p.first == gy && p.second == gx) break;rep(i, 4) {int nx = p.second + dx[i];int ny = p.first + dy[i];if (0 <= ny && ny < w && 0 <= nx && nx < h && visited[nx][ny] == 0) {int h1 = b[nx][ny] - '0';int h2 = b[p.second][p.first] - '0';if (abs(h1 - h2) <= 1) {visited[nx][ny] = 1;que.push(P(ny, nx));}}}rep(i, 4) {int nx = p.second + 2 * dx[i];int ny = p.first + 2 * dy[i];if (0 <= ny && ny < w && 0 <= nx && nx < h && visited[nx][ny] == 0) {int h1 = b[nx][ny] - '0';int h2 = b[p.second][p.first] - '0';int half = b[(nx + p.second) / 2][(ny + p.first) / 2] - '0';if ((h1 == h2) && (h1 - half) > 0) {visited[nx][ny] = 1;que.push(P(ny, nx));}}}}return visited[gx][gy];}int main() {scanf("%d%d", &h, &w);scanf("%d%d%d%d", &sx, &sy, &gx, &gy);rep(i, h) cin >> b[i];if (bfs())printf("YES\n");elseprintf("NO\n");return 0;}