結果

問題 No.424 立体迷路
ユーザー aaaaaaiuaaaaaaiu
提出日時 2019-08-26 23:42:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 908 bytes
コンパイル時間 2,261 ms
コンパイル使用メモリ 200,132 KB
実行使用メモリ 814,720 KB
最終ジャッジ日時 2024-04-26 04:10:06
合計ジャッジ時間 5,285 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int dy[]={0,1,0,-1};
int dx[]={1,0,-1,0};
int h,w;

void dfs(int y,int x,string s[],vector<vector<int>>& v) {
    v[y][x]=1;
    for (int i=0;i<4;i++) {
        int ny=y+dy[i];
        int nx=x+dx[i];
        if (ny<0||h<=ny||nx<0||w<=nx)
            continue;
        if (abs(s[y][x]-s[ny][nx])<=1)
            dfs(ny,nx,s,v);
        int ny2=ny+dy[i];
        int nx2=nx+dx[i];
        if (ny2<0||h<=ny2||nx2<0||w<=nx2)
            continue;
        if (s[y][x]==s[ny2][nx2]&&s[y][x]>s[ny][nx])
            dfs(ny2,nx2,s,v);
    }
}

int main() {
    int sy,sx,gy,gx;
    cin>>h>>w>>sy>>sx>>gy>>gx;
    sy--,sx--,gy--,gx--;
    string s[h];
    for (int i=0;i<h;i++)
        cin>>s[i];
    vector<vector<int>> v(h,vector<int>(w,0));
    dfs(sy,sx,s,v);
    if (v[gy][gx])
        puts("YES");
    else
        puts("NO");
    return 0;
}
0