結果

問題 No.424 立体迷路
ユーザー yosupotyosupot
提出日時 2016-09-22 23:44:48
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,309 bytes
コンパイル時間 840 ms
コンパイル使用メモリ 99,336 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-18 16:51:03
合計ジャッジ時間 1,975 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <vector>
#include <valarray>
#include <array>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <complex>
#include <random>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template<class T = ll> constexpr T TEN(int n) {return (n==0)?1:10*TEN<T>(n-1);}
int bsr(int x) { return 31 - __builtin_clz(x); }

const int MN = 52;
int g[MN][MN];
bool ok[MN][MN];
const int d4[4][2] = {
    {1, 0},
    {0, 1},
    {-1, 0},
    {0, -1},
};

int main() {
    int h, w;
    cin >> h >> w;
    int sy, sx, gy, gx;
    cin >> sy >> sx >> gy >> gx;
    sy--; sx--; gy--; gx--;
    for (int i = 0; i < h; i++) {
        string s;
        cin >> s;
        for (int j = 0; j < w; j++) {
            g[i][j] = s[j]-'0';
        }
    }
    auto bc = [&](int x, int y) {
        return (0 <= x && x < w && 0 <= y && y < h);
    };
    ok[sy][sx] = true;
    while (true) {
        bool update = false;

        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (!ok[i][j]) continue;
                for (int d = 0; d < 4; d++) {
                    int ni = i+2*d4[d][0];
                    int nj = j+2*d4[d][1];
                    int mi = (ni+i)/2;
                    int mj = (nj+j)/2;
                    if (bc(nj, ni) && g[ni][nj] == g[i][j] && g[mi][mj] < g[i][j]) {
                        if (!ok[ni][nj]) {
                            update = true;
                            ok[ni][nj] = true;
                        }
                    }
                }
                for (int d = 0; d < 4; d++) {
                    int ni = i+d4[d][0];
                    int nj = j+d4[d][1];
                    if (bc(nj, ni) && abs(g[ni][nj] - g[i][j]) <= 1) {
                        if (!ok[ni][nj]) {
                            update = true;
                            ok[ni][nj] = true;
                        }
                    }
                }                
            }
        }
        if (!update) break;
    }
    if (ok[gy][gx]) {
        printf("YES\n");
    } else {
        printf("NO\n");
    }
    return 0;
}
0