結果
| 問題 |
No.424 立体迷路
|
| コンテスト | |
| ユーザー |
rsk0315
|
| 提出日時 | 2019-02-01 20:29:30 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,365 bytes |
| コンパイル時間 | 638 ms |
| コンパイル使用メモリ | 79,508 KB |
| 最終ジャッジ日時 | 2025-01-06 20:42:43 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 21 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:16:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
16 | scanf("%zu %zu", &h, &w);
| ~~~~~^~~~~~~~~~~~~~~~~~~
main.cpp:19:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
19 | scanf("%zu %zu %zu %zu", &sy, &sx, &gy, &gx);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:28:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
28 | scanf("%s", buf);
| ~~~~~^~~~~~~~~~~
ソースコード
#include <cstdio>
#include <cstdint>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <utility>
#include <tuple>
static constexpr size_t di[] = {size_t(-1), 0, 1, 0};
static constexpr size_t dj[] = {0, size_t(-1), 0, 1};
int main() {
size_t h, w;
scanf("%zu %zu", &h, &w);
size_t sy, sx, gy, gx;
scanf("%zu %zu %zu %zu", &sy, &sx, &gy, &gx);
--sy;
--sx;
--gy;
--gx;
std::vector<std::string> b(h);
for (size_t i = 0; i < h; ++i) {
char buf[64];
scanf("%s", buf);
b[i] = buf;
}
std::queue<std::pair<size_t, size_t>> q;
std::vector<std::vector<bool>> vis(h, std::vector<bool>(w));
q.emplace(sy, sx);
while (!q.empty()) {
size_t i, j;
std::tie(i, j) = q.front();
q.pop();
if (vis[i][j]) continue;
vis[i][j] = true;
for (int k = 0; k < 4; ++k) {
size_t ni = i + di[k];
size_t nj = j + dj[k];
if (!(ni < h && nj < w)) continue;
int m0 = b[i][j];
int m1 = b[ni][nj];
if (abs(m0-m1) <= 1 && !vis[ni][nj]) {
q.emplace(ni, nj);
}
size_t nni = ni + di[k];
size_t nnj = nj + dj[k];
if (!(nni < h && nnj < w)) continue;
int m2 = b[nni][nnj];
if (m2 == m0 && m2 > m1 && !vis[nni][nnj]) {
q.emplace(nni, nnj);
}
}
}
puts(vis[gy][gx]? "YES":"NO");
}
rsk0315