結果

問題 No.424 立体迷路
ユーザー tokizotokizo
提出日時 2019-02-01 19:41:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,124 bytes
コンパイル時間 1,433 ms
コンパイル使用メモリ 164,516 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-15 15:54:23
合計ジャッジ時間 2,611 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 2 ms
4,384 KB
testcase_13 AC 1 ms
4,384 KB
testcase_14 AC 2 ms
4,384 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,384 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,384 KB
testcase_19 AC 1 ms
4,384 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,388 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 1 ms
4,384 KB
testcase_25 AC 2 ms
4,380 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{
                if(B[x][y] != B[nx][ny]) 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