結果
問題 | No.1638 Robot Maze |
ユーザー | 👑 ygussany |
提出日時 | 2021-08-06 21:33:38 |
言語 | C (gcc 12.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 3,071 bytes |
コンパイル時間 | 997 ms |
コンパイル使用メモリ | 32,768 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-17 01:24:56 |
合計ジャッジ時間 | 1,780 ms |
ジャッジサーバーID (参考情報) |
judge1 / 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 | 2 ms
5,376 KB |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 1 ms
5,376 KB |
testcase_07 | AC | 1 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 | 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 | 1 ms
5,376 KB |
testcase_22 | AC | 1 ms
5,376 KB |
testcase_23 | AC | 1 ms
5,376 KB |
testcase_24 | AC | 1 ms
5,376 KB |
testcase_25 | AC | 1 ms
5,376 KB |
testcase_26 | AC | 1 ms
5,376 KB |
testcase_27 | AC | 2 ms
5,376 KB |
testcase_28 | AC | 2 ms
5,376 KB |
testcase_29 | AC | 1 ms
5,376 KB |
testcase_30 | AC | 1 ms
5,376 KB |
testcase_31 | AC | 1 ms
5,376 KB |
testcase_32 | AC | 1 ms
5,376 KB |
testcase_33 | AC | 2 ms
5,376 KB |
testcase_34 | AC | 2 ms
5,376 KB |
testcase_35 | AC | 2 ms
5,376 KB |
testcase_36 | AC | 2 ms
5,376 KB |
testcase_37 | AC | 1 ms
5,376 KB |
testcase_38 | AC | 2 ms
5,376 KB |
testcase_39 | AC | 2 ms
5,376 KB |
testcase_40 | AC | 2 ms
5,376 KB |
testcase_41 | AC | 2 ms
5,376 KB |
testcase_42 | AC | 2 ms
5,376 KB |
testcase_43 | AC | 2 ms
5,376 KB |
testcase_44 | AC | 2 ms
5,376 KB |
testcase_45 | AC | 2 ms
5,376 KB |
testcase_46 | AC | 2 ms
5,376 KB |
testcase_47 | AC | 2 ms
5,376 KB |
testcase_48 | AC | 2 ms
5,376 KB |
testcase_49 | AC | 2 ms
5,376 KB |
testcase_50 | AC | 2 ms
5,376 KB |
testcase_51 | AC | 2 ms
5,376 KB |
ソースコード
#include <stdio.h> typedef struct { long long key; int id[2]; } data; typedef struct { data obj[100000]; int size; } min_heap; void push(data x, min_heap* h) { int i = ++(h->size), j = i >> 1; data tmp; h->obj[i] = x; while (j > 0) { if (h->obj[i].key < h->obj[j].key) { tmp = h->obj[j]; h->obj[j] = h->obj[i]; h->obj[i] = tmp; i = j; j >>= 1; } else break; } } data pop(min_heap* h) { int i = 1, j = 2; data output = h->obj[1], tmp; h->obj[1] = h->obj[(h->size)--]; while (j <= h->size) { if (j < h->size && h->obj[j^1].key < h->obj[j].key) j ^= 1; if (h->obj[j].key < h->obj[i].key) { tmp = h->obj[j]; h->obj[j] = h->obj[i]; h->obj[i] = tmp; i = j; j = i << 1; } else break; } return output; } int main() { int i, j, H, W, U, D, R, L, s[2], t[2]; long long K, P; char C[102][102] = {}; scanf("%d %d", &H, &W); scanf("%d %d %d %d %lld %lld", &U, &D, &R, &L, &K, &P); scanf("%d %d %d %d", &(s[0]), &(s[1]), &(t[0]), &(t[1])); for (i = 1; i <= H; i++) scanf("%s", &(C[i][1])); const long long sup = 1LL << 60; long long dist[101][101]; min_heap h; data d; for (i = 1; i <= H; i++) for (j = 1; j <= W; j++) dist[i][j] = sup; h.size = 0; dist[s[0]][s[1]] = 0; d.key = 0; d.id[0] = s[0]; d.id[1] = s[1]; push(d, &h); while (h.size > 0) { d = pop(&h); i = d.id[0]; j = d.id[1]; if (d.key != dist[i][j]) continue; if (C[i-1][j] == '.') { if (dist[i-1][j] > dist[i][j] + U) { dist[i-1][j] = dist[i][j] + U; d.key = dist[i-1][j]; d.id[0] = i - 1; d.id[1] = j; push(d, &h); } } else if (C[i-1][j] == '@') { if (dist[i-1][j] > dist[i][j] + U + P) { dist[i-1][j] = dist[i][j] + U + P; d.key = dist[i-1][j]; d.id[0] = i - 1; d.id[1] = j; push(d, &h); } } if (C[i+1][j] == '.') { if (dist[i+1][j] > dist[i][j] + D) { dist[i+1][j] = dist[i][j] + D; d.key = dist[i+1][j]; d.id[0] = i + 1; d.id[1] = j; push(d, &h); } } else if (C[i+1][j] == '@') { if (dist[i+1][j] > dist[i][j] + D + P) { dist[i+1][j] = dist[i][j] + D + P; d.key = dist[i+1][j]; d.id[0] = i + 1; d.id[1] = j; push(d, &h); } } if (C[i][j-1] == '.') { if (dist[i][j-1] > dist[i][j] + L) { dist[i][j-1] = dist[i][j] + L; d.key = dist[i][j-1]; d.id[0] = i; d.id[1] = j - 1; push(d, &h); } } else if (C[i][j-1] == '@') { if (dist[i][j-1] > dist[i][j] + L + P) { dist[i][j-1] = dist[i][j] + L + P; d.key = dist[i][j-1]; d.id[0] = i; d.id[1] = j - 1; push(d, &h); } } if (C[i][j+1] == '.') { if (dist[i][j+1] > dist[i][j] + R) { dist[i][j+1] = dist[i][j] + R; d.key = dist[i][j+1]; d.id[0] = i; d.id[1] = j + 1; push(d, &h); } } else if (C[i][j+1] == '@') { if (dist[i][j+1] > dist[i][j] + R + P) { dist[i][j+1] = dist[i][j] + R + P; d.key = dist[i][j+1]; d.id[0] = i; d.id[1] = j + 1; push(d, &h); } } } if (dist[t[0]][t[1]] > K) printf("No\n"); else printf("Yes\n"); fflush(stdout); return 0; }