結果
問題 | No.1283 Extra Fee |
ユーザー | LyricalMaestro |
提出日時 | 2024-01-24 02:03:02 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,844 bytes |
コンパイル時間 | 171 ms |
コンパイル使用メモリ | 82,120 KB |
実行使用メモリ | 171,468 KB |
最終ジャッジ日時 | 2024-09-28 06:56:49 |
合計ジャッジ時間 | 30,552 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 45 ms
52,992 KB |
testcase_01 | AC | 40 ms
52,884 KB |
testcase_02 | AC | 40 ms
53,248 KB |
testcase_03 | AC | 40 ms
52,992 KB |
testcase_04 | AC | 40 ms
52,992 KB |
testcase_05 | AC | 39 ms
52,480 KB |
testcase_06 | AC | 44 ms
53,504 KB |
testcase_07 | AC | 41 ms
52,992 KB |
testcase_08 | AC | 45 ms
54,144 KB |
testcase_09 | AC | 44 ms
53,376 KB |
testcase_10 | AC | 42 ms
53,504 KB |
testcase_11 | AC | 314 ms
84,388 KB |
testcase_12 | AC | 285 ms
83,536 KB |
testcase_13 | AC | 216 ms
80,548 KB |
testcase_14 | AC | 442 ms
91,604 KB |
testcase_15 | AC | 639 ms
100,380 KB |
testcase_16 | AC | 261 ms
81,824 KB |
testcase_17 | TLE | - |
testcase_18 | AC | 1,916 ms
161,664 KB |
testcase_19 | AC | 1,991 ms
164,176 KB |
testcase_20 | AC | 1,862 ms
158,972 KB |
testcase_21 | AC | 1,929 ms
161,280 KB |
testcase_22 | AC | 1,604 ms
150,680 KB |
testcase_23 | AC | 1,566 ms
153,344 KB |
testcase_24 | AC | 1,721 ms
161,092 KB |
testcase_25 | TLE | - |
testcase_26 | AC | 1,996 ms
167,112 KB |
testcase_27 | TLE | - |
testcase_28 | TLE | - |
testcase_29 | TLE | - |
ソースコード
## https://yukicoder.me/problems/no/1283 import heapq 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 = [[[float("inf"), float("inf")] for _ in range(N)] for _ in range(N)] seen[0][0][0] = 0 fix = [[[float("inf"), float("inf")] for _ in range(N)] for _ in range(N)] queue = [] heapq.heappush(queue, (0, 0, 0, 0)) while len(queue) > 0: cost, h, w, state = heapq.heappop(queue) if fix[h][w][state] <= cost: continue fix[h][w][state] = 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[new_h][new_w][state] != float("inf"): continue new_cost = cost + 1 + pass_map[new_h][new_w] if seen[new_h][new_w][state] > new_cost: seen[new_h][new_w][state] = new_cost heapq.heappush(queue, (new_cost, new_h, new_w, state)) # 免除を使う場合 if state == 0 and pass_map[new_h][new_w] > 0: if fix[new_h][new_w][1] != float("inf"): continue new_cost = cost + 1 if seen[new_h][new_w][1] > new_cost: seen[new_h][new_w][1] = new_cost heapq.heappush(queue, (new_cost, new_h, new_w, 1)) answer = min(fix[N - 1][N - 1]) if answer == float("inf"): print(-1) else: print(answer) if __name__ == "__main__": main()