結果
問題 | No.424 立体迷路 |
ユーザー |
![]() |
提出日時 | 2016-09-22 23:12:35 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 4 ms / 2,000 ms |
コード長 | 1,837 bytes |
コンパイル時間 | 752 ms |
コンパイル使用メモリ | 100,600 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-05 07:06:08 |
合計ジャッジ時間 | 1,480 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 21 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:36:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 36 | scanf("%d %d %d %d %d %d", &h, &w, &s.second, &s.first, &g.second, &g.first); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ main.cpp:43:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 43 | scanf("%*c"); | ~~~~~^~~~~~~ main.cpp:46:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 46 | scanf("%c", &c); | ~~~~~^~~~~~~~~~
ソースコード
#include <iostream>#include <cstdio>#include <vector>#include <cmath>#include <cstring>#include <numeric>#include <algorithm>#include <functional>#include <array>#include <map>#include <queue>#include <limits.h>#include <set>#include <bitset>#include <stack>#include <cstdlib>#include <unordered_map>#define REP(i,n) for(int i = 0; n > i; i++)#define MOD 1000000007#define Range(x,a,b) ((a) <= (x) && (x) <= (b))#define POWT(x) ((x)*(x))using namespace std;typedef vector<int> Ivec;typedef pair<int, int> pii;typedef long long int ll;const pii four_Dir[4] = { //四方向{ 0 ,1 },{ -1 ,0 },{ 1 ,0 },{ 0 ,-1 }};int main() {int h, w;pii s, g;scanf("%d %d %d %d %d %d", &h, &w, &s.second, &s.first, &g.second, &g.first);s.first--;s.second--;g.first--;g.second--;vector<vector<int>> m(w, vector<int>(h));REP(i, h) {scanf("%*c");REP(j, w) {char c;scanf("%c", &c);m[j][i] = c - '0';}}queue<pii> que;map<pii,bool> al;que.push(s);while (que.size()) {auto cur = que.front();que.pop();if (cur == g) {printf("YES\n");return 0;}if (al[cur]) continue;al[cur] = true;REP(i, 4) {pii next = {cur.first + four_Dir[i].first, cur.second + four_Dir[i].second};if (!al[next] && Range(next.first, 0, w-1) && Range(next.second, 0, h-1)) {if (abs(m[cur.first][cur.second] - m[next.first][next.second]) <= 1) {que.push(next);}}next = { next.first + four_Dir[i].first, next.second + four_Dir[i].second };if (!al[next] && Range(next.first, 0, w-1) && Range(next.second, 0, h-1)) {if (m[cur.first][cur.second] > m[next.first - four_Dir[i].first][next.second - four_Dir[i].second] && m[cur.first][cur.second] ==m[next.first][next.second]) {que.push(next);}}}}printf("NO\n");return 0;}