結果

問題 No.424 立体迷路
ユーザー Ai3ShotaAi3Shota
提出日時 2018-06-26 08:12:30
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,275 bytes
コンパイル時間 1,198 ms
コンパイル使用メモリ 147,144 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-18 17:04:23
合計ジャッジ時間 2,272 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

int H, W, Sx, Sy, Gx, Gy;
vector<string> B(51);
bool dp[51][51] = {{0}};

void rec(int x = Sx - 1, int y = Sy - 1, int high = B[Sy - 1][Sx - 1] - '0'){
    
    if(x <= -1 || x >= W || y <= -1 || y >= H) return;
    if(high != B[y][x] - '0') return;
    if(x == Gx - 1 && y == Gy- 1){
        cout << "YES" << endl;
        exit(0);
    }
    
    if(dp[y][x]) return;
    dp[y][x] = true;
    
    rec(x - 1, y, high);
    rec(x + 1, y, high);
    rec(x, y - 1, high);
    rec(x, y + 1, high);
    
    rec(x - 1, y, high + 1);
    rec(x + 1, y, high + 1);
    rec(x, y - 1, high + 1);
    rec(x, y + 1, high + 1);
    
    rec(x - 1, y, high - 1);
    rec(x + 1, y, high - 1);
    rec(x, y - 1, high - 1);
    rec(x, y + 1, high - 1);
    
    if(x - 1 >= 0 && high > B[y][x - 1] - '0') rec(x - 2, y, high);
    if(x + 1 >= 0 && high > B[y][x + 1] - '0') rec(x + 2, y, high);
    if(y - 1 >= 0 && high > B[y - 1][x] - '0') rec(x, y - 2, high);
    if(y + 1 >= 0 && high > B[y + 1][x] - '0') rec(x, y + 2, high);
    
    return;
}

int main(void){
    
    cin >> H >> W >> Sy >> Sx >> Gy >> Gx;
    for(int i = 0; i < H; ++i) cin >> B[i];
    
    rec();
    cout << "NO" << endl;
    
    return 0;
}

0