結果
問題 | No.867 避難経路 |
ユーザー | aaaaaaaaaa2230 |
提出日時 | 2022-05-21 12:48:57 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,580 bytes |
コンパイル時間 | 513 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 371,288 KB |
最終ジャッジ日時 | 2024-09-20 11:34:40 |
合計ジャッジ時間 | 28,570 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 45 ms
54,016 KB |
testcase_01 | AC | 45 ms
54,144 KB |
testcase_02 | AC | 47 ms
53,888 KB |
testcase_03 | AC | 45 ms
54,144 KB |
testcase_04 | AC | 46 ms
54,400 KB |
testcase_05 | AC | 47 ms
54,144 KB |
testcase_06 | AC | 46 ms
54,272 KB |
testcase_07 | AC | 46 ms
54,016 KB |
testcase_08 | AC | 43 ms
54,272 KB |
testcase_09 | AC | 48 ms
60,288 KB |
testcase_10 | AC | 45 ms
54,144 KB |
testcase_11 | AC | 44 ms
53,888 KB |
testcase_12 | AC | 48 ms
54,272 KB |
testcase_13 | AC | 47 ms
53,888 KB |
testcase_14 | AC | 45 ms
53,760 KB |
testcase_15 | AC | 4,663 ms
346,888 KB |
testcase_16 | AC | 5,708 ms
356,372 KB |
testcase_17 | AC | 4,504 ms
347,020 KB |
testcase_18 | AC | 5,915 ms
354,724 KB |
testcase_19 | AC | 5,552 ms
357,504 KB |
testcase_20 | AC | 5,100 ms
359,256 KB |
testcase_21 | TLE | - |
testcase_22 | AC | 5,246 ms
351,360 KB |
testcase_23 | AC | 4,513 ms
346,992 KB |
testcase_24 | TLE | - |
testcase_25 | AC | 5,263 ms
350,244 KB |
testcase_26 | AC | 5,144 ms
349,340 KB |
testcase_27 | AC | 4,884 ms
346,908 KB |
testcase_28 | AC | 4,044 ms
342,604 KB |
testcase_29 | AC | 3,675 ms
341,316 KB |
testcase_30 | TLE | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
testcase_42 | -- | - |
testcase_43 | -- | - |
ソースコード
import sys input = sys.stdin.readline from heapq import heappush,heappop # def divmod(x,mod): # a = x//mod # return a,x-a*mod h,w = map(int,input().split()) gx,gy = [int(x)-1 for x in input().split()] A = [list(map(int,input().split())) for i in range(h)] inf = 10**20 dp = [[[inf]*(500) for i in range(w)] for j in range(h)] dist = [[inf]*w for i in range(h)] step = [[inf]*w for i in range(h)] dist[gx][gy] = A[gx][gy] dp[gx][gy][0] = A[gx][gy] step[gx][gy] = 0 H = [] dx = [1,0,-1,0] dy = [0,1,0,-1] mod2 = 1<<16 heappush(H,(A[gx][gy]<<16)+gx*w+gy) for d in range(500): nH = [] while H: num = heappop(H) c,num = divmod(num,mod2) x,y = divmod(num,w) if dp[x][y][d] != c: continue # print(d,c,x,y) for i in range(4): nx = x+dx[i] ny = y+dy[i] if nx < 0 or nx >= h or ny < 0 or ny >= w: continue nc = c + A[nx][ny] if dist[nx][ny] <= nc: continue if d < 499 and dp[nx][ny][d+1] > nc: dp[nx][ny][d+1] = nc dist[nx][ny] = nc step[nx][ny] = d+1 nnum = (nc<<16)+nx*w+ny heappush(nH,nnum) if nH: H = nH else: break q = int(input()) for _ in range(q): x,y,k = map(int,input().split()) x -= 1 y -= 1 ans = inf k = k**2 nc = k ndp = dp[x][y] for i in range(step[x][y]+1): if ans > ndp[i]+nc: ans = ndp[i]+nc nc += k print(ans)