結果

問題 No.424 立体迷路
ユーザー kimiyukikimiyuki
提出日時 2016-09-22 22:49:03
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,784 bytes
コンパイル時間 904 ms
コンパイル使用メモリ 86,964 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-18 16:46:18
合計ジャッジ時間 2,051 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,384 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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() {
    // input
    int 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';
    }
    // compute
    auto 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);
            }
        }
    }
    // output
    cout << (dp[gy][gx] ? "YES" : "NO") << endl;
    return 0;
}
0