結果

問題 No.424 立体迷路
ユーザー rapurasurapurasu
提出日時 2016-09-23 15:52:02
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,476 bytes
コンパイル時間 1,178 ms
コンパイル使用メモリ 150,028 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-18 16:53:53
合計ジャッジ時間 2,207 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

 #include<bits/stdc++.h>
 using namespace std;
#define INF 1000000000
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
bool dp[51][51];
int g[51][51];
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int main(){
    REP(i,51){
        REP(j,51){
            dp[i][j]=false;
        }
    }
    int h,w,sx,sy,gx,gy;
    cin>>h>>w>>sx>>sy>>gx>>gy;
    REP(i,h){
        string s;
        cin>>s;
        REP(j,w){
            g[i+1][j+1]=s[j]-'0';
        }
    }
    queue<pair<int,int> > que;
    que.push(make_pair(sx,sy));
    dp[sx][sy]=true;
    bool check=false;
    while(!que.empty()){
        pair<int,int> p=que.front();
        if(p.first==gx&&p.second==gy){
           check=true;
           break;
        }
        que.pop();
        REP(i,4){
            int x=p.first+dx[i];
            int y=p.second+dy[i];
            if(x>0&&y>0&&x<=h&&y<=w){
                 if(dp[x][y]==false&&abs(g[p.first][p.second]-g[x][y])<=1){
                    dp[x][y]=true;
                    que.push(make_pair(x,y));
                 }
            }
            
            x+=dx[i];
            y+=dy[i];
            if(x>0&&y>0&&x<=h&&y<=w){
                 if(dp[x][y]==false&&g[p.first][p.second]==g[x][y]&&g[x][y]>=g[(x+p.first)/2][(y+p.second)/2]){
                    dp[x][y]=true;
                    que.push(make_pair(x,y));
                 }
            }
        }
    }
    if(check==true){
       cout<<"YES"<<endl;
    }else{
       cout<<"NO"<<endl;
    }
}
0