結果

問題 No.424 立体迷路
ユーザー kappybarkappybar
提出日時 2020-05-01 20:58:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,523 bytes
コンパイル時間 2,028 ms
コンパイル使用メモリ 180,328 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-26 05:35:14
合計ジャッジ時間 2,870 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll =  long long ;
using P = pair<int,int> ;
using pll = pair<ll,ll>;
constexpr int INF = 1e9;
constexpr ll LINF = 1e18;
constexpr int MOD = 1000000007;
vector<int> dx = {0,0,1,-1,0,0,2,-2};
vector<int> dy = {1,-1,0,0,2,-2,0,0};

int main(){
    int h,w;
    cin >> h >> w;
    int sx,sy,gx,gy;
    cin >> sx >> sy >> gx >> gy;
    --sx;--sy;--gx;--gy;
    vector<string> maze(h);
    rep(i,h) cin >> maze[i];
    vector<vector<bool>> seen(h,vector<bool>(w,false));
    queue<P> q;
    q.push(P(sx,sy));
    while(!q.empty()){
        int x,y;
        tie(x,y) = q.front();
        q.pop();
        if(seen[x][y]) continue;
        seen[x][y] = true;
        rep(i,4){
            int new_x = x + dx[i];
            int new_y = y + dy[i];
            if(0 <= new_x && new_x < h && 0 <= new_y && new_y < w){
                if(abs(maze[x][y]-maze[new_x][new_y]) <= 1 && !seen[new_x][new_y]){
                    q.push(P(new_x,new_y));
                }
            }
        }
        for(int i=4;i<8;i++){
            int new_x = x + dx[i];
            int new_y = y + dy[i];
            if(0 <= new_x && new_x < h && 0 <= new_y && new_y < w){
                if(maze[x][y] == maze[new_x][new_y] && maze[(x+new_x)/2][(y+new_y)/2] < maze[x][y] && !seen[new_x][new_y]){
                    q.push(P(new_x,new_y));
                }
            }
        }
    }
    cout << (seen[gx][gy] ? "YES" : "NO") << endl;
    return 0;
}
0