結果

問題 No.424 立体迷路
ユーザー Konton7Konton7
提出日時 2020-01-15 02:32:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,077 bytes
コンパイル時間 2,306 ms
コンパイル使用メモリ 205,228 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-28 13:42:43
合計ジャッジ時間 3,530 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 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 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 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 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;
typedef long long ll;

int h, w;
vector<vector<int>> field;
vector<vector<int>> field_check;
vector<int> x;

void dfs(int y, int x){
    if (field_check[y][x])
        return;
    else{
        field_check[y][x] = 1;
        if (abs(field[y+1][x] - field[y][x]) <= 1)
            dfs(y+1, x);
        if (abs(field[y-1][x] - field[y][x]) <= 1)
            dfs(y-1, x);
        if (abs(field[y][x+1] - field[y][x]) <= 1)
            dfs(y, x+1);
        if (abs(field[y][x-1] - field[y][x]) <= 1)
            dfs(y, x-1);
        if (y < h && field[y+2][x] == field[y][x] && field[y+1][x] < field[y][x])
            dfs(y+2, x);
        if (y > 1 && field[y-2][x] == field[y][x] && field[y-1][x] < field[y][x])
            dfs(y-2, x);
        if (x < h && field[y][x+2] == field[y][x] && field[y][x+1] < field[y][x])
            dfs(y, x+2);
        if (x > 1 && field[y][x-2] == field[y][x] && field[y][x-1] < field[y][x])
            dfs(y, x-2);
        return;
    }
}

int main(){
    int sy, sx, gy, gx, counter;
    char k;
    cin >> h >> w;
    cin >> sy >> sx >> gy >> gx;
    for (int i = 0; i < h+2; i++){
        for (int i = 0; i < w + 2; i++)
            x.push_back(0);
        field_check.push_back(x);
        x.clear();
    }
        
    for (int i = 0; i < w + 2; i++)
        x.push_back(-2);
    field.push_back(x);
    x.clear();
    
    for (int i = 0; i < h; i++){
        x.push_back(-2);
        for (int j = 0; j < w; j++){
            cin >> k;
            x.push_back(k-48);
        }
        x.push_back(-2);
        field.push_back(x);
        x.clear();
    }

    for (int i = 0; i < w + 2; i++)
        x.push_back(-2);
    field.push_back(x);
    
    // for (auto v : field){
    //     for (auto w : v)
    //         cout << w;
    //     cout << endl;
    // }
    
    dfs(sy, sx);
    
    // for (auto v : field_check){
    //     for (auto w : v)
    //         cout << w;
    //     cout << endl;
    // }

    cout << ( field_check[gy][gx] ? "YES" : "NO" ) << endl;
    return 0;

}
0