結果

問題 No.424 立体迷路
ユーザー tokizotokizo
提出日時 2019-02-01 20:05:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,200 bytes
コンパイル時間 1,536 ms
コンパイル使用メモリ 165,852 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-18 17:06:24
合計ジャッジ時間 2,560 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 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,380 KB
testcase_14 AC 1 ms
4,384 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 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>
using namespace std;

int h, w, sx, sy, gx, gy;
const int MAX = 55;
int B[MAX][MAX];
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};

bool seen[MAX][MAX];

void dfs(int x, int y){
    seen[x][y] = true;
    for(int i = 0; i < 2; i++){
        for(int j = 0; j < 4; j++){
            int nx, ny;
            nx = x + dx[j] * (i + 1);
            ny = y + dy[j] * (i + 1);
            if(nx < 0 or nx >= h or ny < 0 or ny >= w) continue;
            if(seen[nx][ny]) continue;
            if(i == 0){
                if(abs(B[x][y] - B[nx][ny]) > 1) continue;
            }else{
                int bet = B[(x + nx) / 2][(y + ny) / 2];
                if(B[x][y] != B[nx][ny] or B[x][y] < bet) continue;
            }
            dfs(nx, ny);
        }
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> h >> w;
    cin >> sx >> sy >> gx >> gy;
    sx--; sy--; gx--; gy--;

    for(int i = 0; i < h; i++){
        string s;
        cin >> s;
        for(int j = 0; j < w; j++){
            B[i][j] = s[j] - '0';
        }
    }

    dfs(sx, sy);

    if(seen[gx][gy]) cout << "YES" << endl;
    else cout << "NO" << endl;



    return 0;
}
0