結果

問題 No.424 立体迷路
ユーザー hedwig100hedwig100
提出日時 2020-07-29 15:15:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,658 bytes
コンパイル時間 1,656 ms
コンパイル使用メモリ 172,428 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-11 07:16:39
合計ジャッジ時間 2,787 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;
const int dy[4] = {-1,0,1,0};
const int dx[4] = {0,1,0,-1};

int N = 2510;
vector<vector<int>> G(N);
vector<int> visited(N,0);
void dfs(int v) {
    for (int e:G[v]) {
        if (visited[e]) continue;
        visited[e] = 1;
        dfs(e);
    }
}

int main() {
    int H,W; cin >> H >> W;
    N = H*W;
    int sx,sy,gx,gy; cin >> sy >> sx >> gy >> gx;
    --sy; --sx; --gy; --gx;
    vector<vector<int>> grid(H,vector<int>(W));
    rep(i,H) {
        string x; cin >> x;
        rep(j,W) {
            grid[i][j] = x[j] - '0';
        }
    }
    rep(i,H)rep(j,W) {
        rep(k,4) {
            int y = i + dy[k],x = j + dx[k];
            if (y < 0 || y >= H || x < 0 || x >= W) continue;
            if (abs(grid[i][j] - grid[y][x]) <= 1) G[i*W + j].push_back(y*W + x);
        }
        rep(k,4) {
            int y = i + 2*dy[k],x = j + 2*dx[k];
            int my = i + dy[k],mx = j + dx[k];
            if (y < 0 || y >= H || x < 0 || x >= W) continue;
            if (grid[i][j] == grid[y][x] && grid[my][mx] < grid[i][j]) G[i*W + j].push_back(y*W + x);
        }
    }
    visited[sy * W + sx] = 1;
    dfs(sy * W + sx);
    if (visited[gy * W + gx]) cout << "YES" << '\n';
    else cout << "NO" << '\n';
    return 0;
}
0