結果
問題 | No.424 立体迷路 |
ユーザー | olphe |
提出日時 | 2016-09-22 23:05:35 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 2,046 bytes |
コンパイル時間 | 428 ms |
コンパイル使用メモリ | 49,536 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-04-28 19:54:51 |
合計ジャッジ時間 | 1,233 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 1 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 1 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 1 ms
5,376 KB |
testcase_14 | AC | 1 ms
5,376 KB |
testcase_15 | AC | 2 ms
5,376 KB |
testcase_16 | AC | 1 ms
5,376 KB |
testcase_17 | AC | 1 ms
5,376 KB |
testcase_18 | AC | 1 ms
5,376 KB |
testcase_19 | AC | 1 ms
5,376 KB |
testcase_20 | AC | 1 ms
5,376 KB |
testcase_21 | AC | 2 ms
5,376 KB |
testcase_22 | AC | 1 ms
5,376 KB |
testcase_23 | AC | 1 ms
5,376 KB |
testcase_24 | AC | 2 ms
5,376 KB |
testcase_25 | AC | 1 ms
5,376 KB |
コンパイルメッセージ
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; }