結果
問題 | No.1283 Extra Fee |
ユーザー | LyricalMaestro |
提出日時 | 2024-01-24 02:11:29 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,925 ms / 2,000 ms |
コード長 | 1,817 bytes |
コンパイル時間 | 355 ms |
コンパイル使用メモリ | 82,196 KB |
実行使用メモリ | 106,024 KB |
最終ジャッジ日時 | 2024-09-28 06:57:13 |
合計ジャッジ時間 | 21,716 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 45 ms
52,736 KB |
testcase_01 | AC | 44 ms
52,868 KB |
testcase_02 | AC | 45 ms
53,248 KB |
testcase_03 | AC | 44 ms
52,864 KB |
testcase_04 | AC | 43 ms
52,864 KB |
testcase_05 | AC | 43 ms
52,864 KB |
testcase_06 | AC | 47 ms
53,632 KB |
testcase_07 | AC | 44 ms
52,992 KB |
testcase_08 | AC | 48 ms
53,504 KB |
testcase_09 | AC | 46 ms
53,120 KB |
testcase_10 | AC | 45 ms
52,992 KB |
testcase_11 | AC | 259 ms
78,744 KB |
testcase_12 | AC | 268 ms
78,564 KB |
testcase_13 | AC | 187 ms
77,572 KB |
testcase_14 | AC | 341 ms
80,064 KB |
testcase_15 | AC | 471 ms
81,712 KB |
testcase_16 | AC | 200 ms
77,816 KB |
testcase_17 | AC | 1,799 ms
104,060 KB |
testcase_18 | AC | 1,374 ms
94,492 KB |
testcase_19 | AC | 1,328 ms
93,528 KB |
testcase_20 | AC | 1,222 ms
92,384 KB |
testcase_21 | AC | 1,261 ms
92,904 KB |
testcase_22 | AC | 1,111 ms
91,024 KB |
testcase_23 | AC | 1,135 ms
89,304 KB |
testcase_24 | AC | 1,148 ms
89,344 KB |
testcase_25 | AC | 1,362 ms
94,600 KB |
testcase_26 | AC | 1,351 ms
94,452 KB |
testcase_27 | AC | 1,319 ms
93,796 KB |
testcase_28 | AC | 1,359 ms
94,444 KB |
testcase_29 | AC | 1,925 ms
106,024 KB |
ソースコード
## https://yukicoder.me/problems/no/1283 import heapq MAX_INT = 10 ** 18 def main(): N, M = map(int, input().split()) pass_map = [[0] * N for _ in range(N)] for _ in range(M): h, w, c = map(int, input().split()) pass_map[h - 1][w - 1] = c seen = [[[MAX_INT] * N for _ in range(N)] for _ in range(2)] seen[0][0][0] = 0 fix = [[[MAX_INT] * N for _ in range(N)] for _ in range(2)] queue = [] heapq.heappush(queue, (0, 0, 0, 0)) while len(queue) > 0: cost, state, h, w = heapq.heappop(queue) if fix[state][h][w] <= cost: continue fix[state][h][w] = cost for dh, dw in ((0, 1), (1, 0), (0, -1), (-1, 0)): new_h = h + dh new_w = w + dw if 0 <= new_h and new_h < N and 0 <= new_w and new_w < N: # 普通に手数料を払う場合 if fix[state][new_h][new_w] >= MAX_INT: new_cost = cost + 1 + pass_map[new_h][new_w] if seen[state][new_h][new_w] > new_cost: seen[state][new_h][new_w] = new_cost heapq.heappush(queue, (new_cost, state, new_h, new_w)) # 免除を使う場合 if state == 0 and pass_map[new_h][new_w] > 0: if fix[1][new_h][new_w] >= MAX_INT: new_cost = cost + 1 if seen[1][new_h][new_w] > new_cost: seen[1][new_h][new_w] = new_cost heapq.heappush(queue, (new_cost, 1, new_h, new_w)) answer = min(fix[0][N - 1][N - 1], fix[1][N - 1][N - 1]) if answer == float("inf"): print(-1) else: print(answer) if __name__ == "__main__": main()