結果
問題 | No.424 立体迷路 |
ユーザー |
|
提出日時 | 2016-09-22 22:49:03 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,784 bytes |
コンパイル時間 | 780 ms |
コンパイル使用メモリ | 87,600 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-05 07:02:46 |
合計ジャッジ時間 | 1,481 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 21 |
ソースコード
#include <iostream>#include <vector>#include <queue>#include <tuple>#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))using namespace std;template <typename T, typename X> auto vectors(T a, X x) { return vector<T>(x, a); }template <typename T, typename X, typename Y, typename... Zs> auto vectors(T a, X x, Y y, Zs... zs) { auto cont = vectors(a, y, zs...); return vector<decltype(cont)>(x, cont); }const int dy[] = { -1, 1, 0, 0 };const int dx[] = { 0, 0, 1, -1 };int main() {// inputint h, w; cin >> h >> w;int sy, sx, gy, gx; cin >> sy >> sx >> gy >> gx;-- sy; -- sx; -- gy; -- gx;vector<vector<int> > f = vectors(int(), h, w);repeat (y,h) repeat (x,w) {char c; scanf(" %c", &c);f[y][x] = c-'0';}// computeauto is_on_field = [&](int y, int x) { return 0 <= y and y < h and 0 <= x and x < w; };vector<vector<bool> > dp = vectors(false, h, w);queue<pair<int,int> > que;auto push = [&](int y, int x) {if (dp[y][x]) return;dp[y][x] = true;que.emplace(y, x);};push(sy, sx);while (not que.empty()) {int y, x; tie(y, x) = que.front(); que.pop();repeat (i,4) {int ny = y + dy[i];int nx = x + dx[i];if (not is_on_field(ny, nx)) continue;if (abs(f[ny][nx] - f[y][x]) <= 1) {push(ny, nx);}}repeat (i,4) {int ny = y + 2*dy[i];int nx = x + 2*dx[i];if (not is_on_field(ny, nx)) continue;if (f[ny][nx] == f[y][x] and f[y + dy[i]][x + dx[i]] < f[y][x]) {push(ny, nx);}}}// outputcout << (dp[gy][gx] ? "YES" : "NO") << endl;return 0;}