結果
問題 | No.424 立体迷路 |
ユーザー | olphe |
提出日時 | 2016-09-22 23:07:22 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 2,083 bytes |
コンパイル時間 | 352 ms |
コンパイル使用メモリ | 44,416 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-05 07:06:01 |
合計ジャッジ時間 | 1,077 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,376 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 1 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 | 1 ms
5,376 KB |
testcase_09 | AC | 1 ms
5,376 KB |
testcase_10 | AC | 1 ms
5,376 KB |
testcase_11 | AC | 1 ms
5,376 KB |
testcase_12 | AC | 1 ms
5,376 KB |
testcase_13 | AC | 1 ms
5,376 KB |
testcase_14 | AC | 2 ms
5,376 KB |
testcase_15 | AC | 1 ms
5,376 KB |
testcase_16 | AC | 2 ms
5,376 KB |
testcase_17 | AC | 1 ms
5,376 KB |
testcase_18 | AC | 2 ms
5,376 KB |
testcase_19 | AC | 2 ms
5,376 KB |
testcase_20 | AC | 2 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:24:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 24 | scanf("%d %d", &H, &W); | ~~~~~^~~~~~~~~~~~~~~~~ main.cpp:25:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 25 | scanf("%d %d %d %d", &now.first, &now.second, &goal.first, &goal.second); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ main.cpp:27:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 27 | scanf("%s", hei[i]); | ~~~~~^~~~~~~~~~~~~~
ソースコード
#include "stdio.h" #include "queue" #include "utility" 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 abs(int a) { if (a > 0)return a; return a*-1; } 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; }