結果
| 問題 |
No.424 立体迷路
|
| コンテスト | |
| ユーザー |
w10y26
|
| 提出日時 | 2017-07-03 13:04:57 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,940 bytes |
| コンパイル時間 | 1,120 ms |
| コンパイル使用メモリ | 98,604 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-05 11:07:47 |
| 合計ジャッジ時間 | 1,523 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 3 |
| other | AC * 11 WA * 10 |
ソースコード
#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 100000000
using 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;
int bfs() {
rep(i, h) rep(j, w) visited[i][j] = 0;
queue<P> que;
sx--;
sy--;
gx--;
gy--;
que.push(P(sy, sx));
visited[sy][sx] = 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 < h && 0 <= nx && nx < w && visited[ny][nx] == 0) {
int h1 = b[ny][nx] - '0';
int h2 = b[p.first][p.second] - '0';
if (abs(h1 - h2) <= 1) {
visited[ny][nx] = 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 < h && 0 <= nx && nx < w && visited[ny][nx] == 0) {
int h1 = b[ny][nx] - '0';
int h2 = b[p.first][p.second] - '0';
int half = b[(ny + p.first) / 2][(nx + p.second) / 2] - '0';
if ((h1 == h2) && (h1 - half) > 0) {
visited[ny][nx] = 1;
que.push(P(ny, nx));
}
}
}
}
return b[gy][gx];
}
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");
else
printf("NO\n");
return 0;
}
w10y26