結果
| 問題 |
No.424 立体迷路
|
| コンテスト | |
| ユーザー |
okayunonaha
|
| 提出日時 | 2016-09-23 00:10:05 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,633 bytes |
| コンパイル時間 | 409 ms |
| コンパイル使用メモリ | 57,712 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-17 15:16:08 |
| 合計ジャッジ時間 | 1,097 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 WA * 1 |
| other | AC * 17 WA * 4 |
ソースコード
#include <iostream>
#include <string>
using namespace std;
string b[52];
bool is_search[52][52];
int xvec[4] = {-1, 0, 1, 0}, yvec[4] = {0, -1, 0, 1};
int xvec2[4] = {-2, 0, 2, 0}, yvec2[4] = {0, -2, 0, 2};
int h, w;
void dfs(int y, int x) {
//cout << "now is " << x << " " << y << endl;
is_search[y][x] = true;
char nows = b[y][x];
int nowtmp = (int)nows - '0';
for (int i = 0; i < 4; i++) {
if (x + xvec[i] < 0 || x + xvec[i] > w-1 || y + yvec[i] < 0 || y + yvec[i] > h-1) continue;
char stmp = b[y + yvec[i]][x + xvec[i]];
int tmp = (int)stmp - '0';
//cout << tmp << endl;;
if(is_search[y + yvec[i]][x + xvec[i]] == false && (nowtmp == tmp + 1 || nowtmp == tmp - 1 || nowtmp == tmp)) {
dfs(y + yvec[i], x + xvec[i]);
}
if (x + xvec2[i] < 0 || x + xvec2[i] > w-1 || y + yvec2[i] < 0 || y + yvec2[i] > h-1) continue;
char sstmp = b[y + yvec2[i]][x + xvec2[i]];
int ttmp = (int)sstmp - '0';
//cout << ttmp << endl;;
if(is_search[y + yvec2[i]][x + xvec2[i]] == false && nowtmp == ttmp) {
if (ttmp > tmp) dfs(y + yvec2[i], x + xvec2[i]);
}
}
}
int main(void) {
int sx, sy, gx, gy;
cin >> h >> w;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
is_search[i][j] = false;
}
}
cin >> sx >> sy >> gx >> gy;
for (int i = 0; i < h; i++) {
cin >> b[i];
}
dfs(sx-1, sy-1);
/*for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
cout << is_search[i][j] << " ";
}
cout << endl;
}*/
if(is_search[gy-1][gx-1]) cout << "YES" << endl;
else cout << "NO" << endl;
return 0;
}
okayunonaha