結果
問題 | No.1283 Extra Fee |
ユーザー | nok0 |
提出日時 | 2020-09-05 19:22:54 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,559 ms / 2,000 ms |
コード長 | 1,270 bytes |
コンパイル時間 | 262 ms |
コンパイル使用メモリ | 82,192 KB |
実行使用メモリ | 102,288 KB |
最終ジャッジ日時 | 2024-11-16 06:27:12 |
合計ジャッジ時間 | 16,324 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 37 ms
52,628 KB |
testcase_01 | AC | 40 ms
53,764 KB |
testcase_02 | AC | 35 ms
54,092 KB |
testcase_03 | AC | 35 ms
53,092 KB |
testcase_04 | AC | 36 ms
53,636 KB |
testcase_05 | AC | 37 ms
52,964 KB |
testcase_06 | AC | 41 ms
54,868 KB |
testcase_07 | AC | 36 ms
54,016 KB |
testcase_08 | AC | 37 ms
55,276 KB |
testcase_09 | AC | 38 ms
53,968 KB |
testcase_10 | AC | 38 ms
54,796 KB |
testcase_11 | AC | 211 ms
79,068 KB |
testcase_12 | AC | 193 ms
77,840 KB |
testcase_13 | AC | 139 ms
77,472 KB |
testcase_14 | AC | 244 ms
78,744 KB |
testcase_15 | AC | 358 ms
79,968 KB |
testcase_16 | AC | 165 ms
77,404 KB |
testcase_17 | AC | 1,402 ms
101,148 KB |
testcase_18 | AC | 949 ms
89,400 KB |
testcase_19 | AC | 936 ms
88,720 KB |
testcase_20 | AC | 889 ms
88,192 KB |
testcase_21 | AC | 910 ms
88,636 KB |
testcase_22 | AC | 813 ms
86,860 KB |
testcase_23 | AC | 792 ms
85,024 KB |
testcase_24 | AC | 797 ms
85,104 KB |
testcase_25 | AC | 995 ms
90,160 KB |
testcase_26 | AC | 974 ms
89,144 KB |
testcase_27 | AC | 973 ms
89,412 KB |
testcase_28 | AC | 1,009 ms
89,168 KB |
testcase_29 | AC | 1,559 ms
102,288 KB |
ソースコード
import sys from heapq import heappush,heappop readline = sys.stdin.buffer.readline INF = int(1e15) dh = [1,0,-1,0] dw = [0,1,0,-1] N, M = map(int,readline().split()) dist0 = [[INF for j in range(N)] for i in range(N)] dist1 = [[INF for j in range(N)] for i in range(N)] c = [[0 for j in range(N)] for i in range(N)] dist0[0][0] = 0 dist1[0][0] = 0 for i in range(M): H, W, C = map(int,readline().split()) H -= 1 W -= 1 c[H][W] = C q = [(0,0,0,0)] while q: C, H, W, used = heappop(q) if(used == 0 and dist0[H][W] < C): continue if(used == 1 and dist1[H][W] < C): continue for i in range(4): nH = H + dh[i] nW = W + dw[i] if(nH < 0 or nH >= N): continue if(nW < 0 or nW >= N): continue nC0 = C + c[nH][nW] + 1 nC1 = C + 1 if(used == 0): if(dist0[nH][nW] > nC0): heappush(q,(nC0,nH,nW,0)) dist0[nH][nW] = nC0 if(dist1[nH][nW] > nC1): heappush(q,(nC1,nH,nW,1)) dist1[nH][nW] = nC1 else: if(dist1[nH][nW] > nC0): heappush(q,(nC0,nH,nW,1)) dist1[nH][nW] = nC0 print(min(dist0[N-1][N-1],dist1[N-1][N-1]))