結果
問題 |
No.424 立体迷路
|
ユーザー |
|
提出日時 | 2025-09-04 11:50:17 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 1,459 bytes |
コンパイル時間 | 3,749 ms |
コンパイル使用メモリ | 293,400 KB |
実行使用メモリ | 7,716 KB |
最終ジャッジ日時 | 2025-09-04 11:50:23 |
合計ジャッジ時間 | 5,266 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 21 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i< (n); ++i) #define repi(i, a, b) for (int i = (a); i < (b); ++i) #define all(x) (x).begin(), (x).end() #define fore(i, a) for(auto &i:a) using ll = long long; int main() { ll h, w, sx, sy, gx, gy; cin >> h >> w >> sx >> sy >> gx >> gy; sx--;sy--;gx--;gy--; vector<vector<ll>> height(h, vector<ll>(w, 0)); char temp; rep(i, h)rep(j, w){ cin >> temp; height[i][j] = temp - '0'; } vector<vector<bool>> is_reachalbe(h, vector<bool>(w, false)); queue<pair<ll,ll>> q; q.push({sx,sy}); is_reachalbe[sx][sy] = true; vector<int> di = {1, 0, -1, 0}; vector<int> dj = {0, 1, 0, -1}; auto hantei = [&](ll x, ll y){ return x >= 0 && x < h && y >= 0 && y < w; }; while(!q.empty()){ auto[x, y] = q.front(); q.pop(); ll nx, ny; rep(d, 4){ nx = x+di[d];ny = y+dj[d]; if(!hantei(nx,ny) || is_reachalbe[nx][ny]) continue; if(abs(height[x][y] - height[nx][ny]) <= 1){ is_reachalbe[nx][ny] = true; q.push({nx,ny}); } } ll ax, ay; rep(d, 4){ nx = x+di[d]*2;ny = y+dj[d]*2; ax = x+di[d];ay = y+dj[d]; if(!hantei(nx,ny) || is_reachalbe[nx][ny]) continue; if(height[x][y] == height[nx][ny] && height[ax][ay] < height[x][y]){ is_reachalbe[nx][ny] = true; q.push({nx,ny}); } } } if(is_reachalbe[gx][gy])cout << "YES" << endl; else cout << "NO" << endl; }