結果
| 問題 |
No.424 立体迷路
|
| コンテスト | |
| ユーザー |
sekiya9311
|
| 提出日時 | 2016-09-22 22:54:08 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 157 ms / 2,000 ms |
| コード長 | 3,037 bytes |
| コンパイル時間 | 1,240 ms |
| コンパイル使用メモリ | 118,320 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-05 07:04:31 |
| 合計ジャッジ時間 | 2,209 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 21 |
ソースコード
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a)-1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a)-1; (i) >= (b); (i)--)
#define PI acos(-1.0)
#define DEBUG(C) cerr << C << endl;
#define VI vector <int>
#define VII vector <VI>
#define VL vector <LL>
#define VLL vector <VL>
#define VD vector <double>
#define VDD vector <VD>
#define PII pair <int, int>
#define PDD pair <double, double>
#define PLL pair <LL, LL>
#define VPII vector <PII>
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define REVERSE(a) reverse(ALL(a))
#define MP make_pair
#define FORE(a, b) for (auto &&a:b)
#define FIND(s, e) (s.find(e) != s.end())
#define EB emplace_back
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
int hx[] = {0, 0, -2, 2};
int hy[] = {2, -2, 0, 0};
int H, W;
PII start, goal;
vector <string> b;
vector <vector <bool>> is;
#define X first
#define Y second
bool inside(int x, int y) {
bool res = true;
if (x < 0 || H <= x) res = false;
if (y < 0 || W <= x) res = false;
return res;
}
bool dfs(PII now) {
cerr << now.X << " " << now.Y << endl;
if (now == goal) {
return true;
}
int nx = now.X, ny = now.Y;
if (is[nx][ny]) {
return false;
}
is[nx][ny] = true;
REP(i, 4) {
int ndx = nx + dx[i];
int ndy = ny + dy[i];
cerr << ndx << " " << ndy << endl;
if (!inside(ndx, ndy)) continue;
if (abs(b[nx][ny] - b[ndx][ndy]) <= 1 && dfs({ndx, ndy})) {
return true;
}
}
REP(i, 4) {
int ndx = nx + dx[i];
int ndy = ny + dy[i];
int nhx = nx + hx[i];
int nhy = ny + hy[i];
cerr << nhx << " " << nhy << endl;
if (!inside(nhx, nhy)) continue;
if (abs(b[nx][ny] - b[nhx][nhy])) continue;
if (b[nx][ny] <= b[ndx][ndy]) continue;
if (dfs({nhx, nhy})) {
return true;
}
}
return false;
}
int main(void) {
cin >> H >> W;
b.resize(H);
is.resize(H);
cin >> start.X >> start.Y;
cin >> goal.X >> goal.Y;
start.X--;start.Y--;
goal.X--;goal.Y--;
REP(i, H) {
cin >> b[i];
is[i].resize(W, false);
}
if (dfs(start)) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
sekiya9311