結果
問題 | No.424 立体迷路 |
ユーザー |
|
提出日時 | 2016-09-22 23:05:35 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 2,046 bytes |
コンパイル時間 | 516 ms |
コンパイル使用メモリ | 49,408 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-17 15:05:35 |
合計ジャッジ時間 | 987 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 21 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:20:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 20 | scanf("%d %d", &H, &W); | ~~~~~^~~~~~~~~~~~~~~~~ main.cpp:21:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 21 | scanf("%d %d %d %d", &now.first, &now.second, &goal.first, &goal.second); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ main.cpp:23:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 23 | scanf("%s", hei[i]); | ~~~~~^~~~~~~~~~~~~~
ソースコード
#include "stdio.h"#include "queue"#include "utility"#include "math.h"using namespace std;typedef pair<int, int>P;P now;P goal;P box;int H, W;char hei[51][51];int height[51][51];int dx[8] = { 1,0,-1,0,2,0,-2,0 };int dy[8] = { 0,-1,0,1,0,-2,0,2 };queue <P> Q;int dis[51][51];int main() {scanf("%d %d", &H, &W);scanf("%d %d %d %d", &now.first, &now.second, &goal.first, &goal.second);for (int i = 1; i <= H; i++) {scanf("%s", hei[i]);}for (int i = 1; i <= H; i++) {for (int j = W; j >= 1; j--) {hei[i][j] = hei[i][j - 1];height[i][j] = hei[i][j] - '0';//printf("%d", height[i][j]);}}Q.push(now);for (int i = 1; i <= H; i++) {for (int j = 1; j <= W; j++) {dis[i][j] = 10000;}}dis[now.first][now.second] = 0;while (!Q.empty()) {now = Q.front();// printf("%d %dを調べる\n", now.first, now.second);for (int i = 0; i < 8; i++) {if (now.first + dy[i] >= 1 && now.first + dy[i] <= H&&now.second + dx[i] >= 1 && now.second + dx[i] <= W) {if (i < 4) {if (abs(height[now.first][now.second] - height[now.first + dy[i]][now.second + dx[i]])<2) {if (dis[now.first][now.second] + 1 < dis[now.first + dy[i]][now.second + dx[i]]) {dis[now.first + dy[i]][now.second + dx[i]] = dis[now.first][now.second] + 1;box.first = now.first + dy[i];box.second = now.second + dx[i];Q.push(box);}}}else {if (height[now.first][now.second] == height[now.first + dy[i]][now.second + dx[i]]) {if (height[now.first][now.second] > height[now.first + dy[i] / 2][now.second + dx[i] / 2]) {if (dis[now.first][now.second] + 1 < dis[now.first + dy[i]][now.second + dx[i]]) {dis[now.first + dy[i]][now.second + dx[i]] = dis[now.first][now.second] + 1;box.first = now.first + dy[i];box.second = now.second + dx[i];Q.push(box);}}}}}}Q.pop();}if (dis[goal.first][goal.second] != 10000)printf("YES\n");else printf("NO\n");return 0;}