結果
| 問題 |
No.424 立体迷路
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-07-02 22:19:13 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,647 bytes |
| コンパイル時間 | 648 ms |
| コンパイル使用メモリ | 80,084 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-05 07:14:24 |
| 合計ジャッジ時間 | 1,420 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 21 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:66:31: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
66 | scanf("%1d",&field[i][j]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~
ソースコード
#include<cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#define mod 1000000007;
using namespace std;
typedef long long ll;
typedef pair<ll, ll> Pr;
int h, w;
int sx, sy, gx, gy;
int field[55][55];
int used[55][55];
bool flag = false;
int dx[] = { -1,0,1,0 }, dy[] = { 0,1,0,-1 };
int solve() {
queue<Pr> q;
q.push({ sy,sx });
used[sx][sy] = 1;
while (!q.empty()) {
int x = q.front().first;
int y = q.front().second;
q.pop();
for (int i = 0; i < 4; i++) {
int ddx = dx[i] + x, ddy = dy[i] + y;
if (ddx >= 0 && ddx < w && ddy >= 0 && ddy < h ) {
if (abs(field[y][x] - field[ddy][ddx] )<=1 && used[ddy][ddx] == 0) {
used[ddy][ddx] = 1;
//cout << "ddx1 = " << ddx << " ddy1 = " << ddy << " d = " << field[y][x] - field[ddy][ddx] << endl;
q.push({ddx,ddy});
}
if (ddx + dx[i] >= 0 && ddx + dx[i] < w && ddy + dy[i] >= 0 && ddy + dy[i] < h
&& used[ddy+dy[i]][ddx+dx[i]] == 0) {
if (field[y][x] == field[ddy+dy[i]][ddx+dx[i]] && field[ddy][ddx] < field[y][x]) {
// cout << "ddx2 = " << ddx+dx[i] << " ddy2 = " << ddy+dy[i] << endl;
used[ddy + dy[i]][ddx + dx[i]] = 1;
q.push({ddx+dx[i],ddy+dy[i]});
}
}
}
}
}
return used[gx][gy];
}
int main()
{
cin >> h >> w;
cin >> sx >> sy >> gx >> gy;
sx--, sy--, gx--, gy--;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
scanf("%1d",&field[i][j]);
}
}
if (solve())cout << "YES" << endl;
else cout << "NO" << endl;
return 0;
}