結果
| 問題 |
No.424 立体迷路
|
| コンテスト | |
| ユーザー |
misora192
|
| 提出日時 | 2020-05-21 08:38:56 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,458 bytes |
| コンパイル時間 | 1,658 ms |
| コンパイル使用メモリ | 177,236 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-01 23:53:51 |
| 合計ジャッジ時間 | 2,687 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 21 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)
using namespace std;
typedef long long ll;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
vector<int> dr = {1, 0, -1, 0};
vector<int> dc = {0, 1, 0, -1};
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int h, w;
cin >> h >> w;
int sx, sy, gx, gy;
cin >> sx >> sy >> gx >> gy;
sx--; sy--; gx--; gy--;
vector<vector<int>> g(h, vector<int>(w));
rep(i, h) {
string s;
cin >> s;
rep(j, w) g[i][j] = s[j] - '0';
}
int INF = INT_MAX / 10;
vector<vector<int>> d(h, vector<int>(w, INF));
d[sx][sy] = 0;
queue<int> qr, qc;
qr.push(sx); qc.push(sy);
while(!qr.empty()){
int r = qr.front(), c = qc.front();
qr.pop(); qc.pop();
if(r == gx && c == gy){
cout << "YES" << endl;
exit(0);
}
rep(i, 4){
int nr = r + dr[i];
int nc = c + dc[i];
if(0 <= nr && nr < h && 0 <= nc && nc < w){
if(d[nr][nc] > d[r][c] + 1 && abs(g[nr][nc] - g[r][c]) <= 1){
d[nr][nc] = d[r][c] + 1;
qr.push(nr); qc.push(nc);
}
}
nr += dr[i];
nc += dc[i];
if(0 <= nr && nr < h && 0 <= nc && nc < w){
if(d[nr][nc] > d[r][c] + 1 && abs(g[nr][nc] - g[r][c]) == 0 && g[nr-dr[i]][nc-dc[i]] < g[r][c]){
d[nr][nc] = d[r][c] + 1;
qr.push(nr); qc.push(nc);
}
}
}
}
cout << "NO" << endl;
}
misora192