結果

問題 No.424 立体迷路
ユーザー recososorecososo
提出日時 2020-02-25 18:51:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,279 bytes
コンパイル時間 2,166 ms
コンパイル使用メモリ 175,140 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 14:00:53
合計ジャッジ時間 5,635 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int main(){
    int h,w;cin >> h >> w;
    int sx,sy,gx,gy;
    cin >> sx >> sy >> gx >> gy;
    sx--,sy--,gx--,gy--;
    vector<string> b(h);
    for(int i=0;i<h;i++){
        cin >> b[i];
    }
    vector<vector<bool>> re(h,vector<bool>(w));
    queue<pair<int,int>> q;
    q.push({sx,sy});
    re[sx][sy]=true;
    while(!q.empty()){
        int u=q.front().first,v=q.front().second;
        q.pop();
        int s=b[u][v]-'0';
        for(int i=0;i<4;i++){
            int x=u+dx[i],y=v+dy[i];
            int t=b[x][y]-'0';
            if(x>=0&&x<=h-1&&y>=0&&y<=w-1){
                if(!re[x][y]&&abs(t-s)<=1){
                    q.push({x,y});
                    re[x][y]=true;
                }
            }
        }
        for(int i=0;i<4;i++){
            int x=u+dx[i]*2,y=v+dy[i]*2;
            if(x>=0&&x<=h-1&&y>=0&&y<=w-1){
                int t=b[x][y]-'0';
                int w=b[(u+x)/2][(v+y)/2]-'0';
                if(!re[x][y]&&s==t&&w<s){
                    q.push({x,y});
                    re[x][y]=true;
                }
            }
        }
    }
    if(re[gx][gy]){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}
0