結果
| 問題 |
No.424 立体迷路
|
| コンテスト | |
| ユーザー |
tokizo
|
| 提出日時 | 2019-02-01 19:41:18 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,124 bytes |
| コンパイル時間 | 1,549 ms |
| コンパイル使用メモリ | 167,120 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-23 23:34:42 |
| 合計ジャッジ時間 | 2,500 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 19 WA * 2 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int h, w, sx, sy, gx, gy;
const int MAX = 55;
int B[MAX][MAX];
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};
bool seen[MAX][MAX];
void dfs(int x, int y){
seen[x][y] = true;
for(int i = 0; i < 2; i++){
for(int j = 0; j < 4; j++){
int nx, ny;
nx = x + dx[j] * (i + 1);
ny = y + dy[j] * (i + 1);
if(nx < 0 or nx >= h or ny < 0 or ny >= w) continue;
if(seen[nx][ny]) continue;
if(i == 0){
if(abs(B[x][y] - B[nx][ny]) > 1) continue;
}else{
if(B[x][y] != B[nx][ny]) continue;
}
dfs(nx, ny);
}
}
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
cin >> h >> w;
cin >> sx >> sy >> gx >> gy;
sx--; sy--; gx--; gy--;
for(int i = 0; i < h; i++){
string s;
cin >> s;
for(int j = 0; j < w; j++){
B[i][j] = s[j] - '0';
}
}
dfs(sx, sy);
if(seen[gx][gy]) cout << "YES" << endl;
else cout << "NO" << endl;
return 0;
}
tokizo