結果
| 問題 |
No.158 奇妙なお使い
|
| コンテスト | |
| ユーザー |
titia
|
| 提出日時 | 2022-03-28 04:28:40 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,490 bytes |
| コンパイル時間 | 239 ms |
| コンパイル使用メモリ | 82,632 KB |
| 実行使用メモリ | 233,300 KB |
| 最終ジャッジ日時 | 2024-11-06 20:49:19 |
| 合計ジャッジ時間 | 10,442 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 17 TLE * 1 -- * 9 |
ソースコード
import heapq
A=list(map(int,input().split()))
DB=int(input())
B=list(map(int,input().split()))
DC=int(input())
C=list(map(int,input().split()))
DP=dict()
DP[tuple(A)]=0
Q=[(0,A[0],A[1],A[2])]
def calc_b(x,y,z):
money=DB
k=money//1000
MIN=min(k,x)
x-=MIN
money-=MIN*1000
k=money//100
MIN=min(k,y)
y-=MIN
money-=MIN*100
z-=money
if x>=0 and y>=0 and z>=0:
return x+B[0],y+B[1],z+B[2]
return -1,-1,-1
def calc_c(x,y,z):
money=DC
k=money//1000
MIN=min(k,x)
x-=MIN
money-=MIN*1000
k=money//100
MIN=min(k,y)
y-=MIN
money-=MIN*100
z-=money
if x>=0 and y>=0 and z>=0:
return x+C[0],y+C[1],z+C[2]
return -1,-1,-1
while Q:
time,a,b,c=heapq.heappop(Q)
if DP[a,b,c]!=time:
continue
a2,b2,c2=calc_b(a,b,c)
if a2>=0 and b2>=0 and c2>=0:
if (a2,b2,c2) in DP:
if DP[(a2,b2,c2)]>time-1:
DP[a2,b2,c2]=time-1
heapq.heappush(Q,(time-1,a2,b2,c2))
else:
DP[a2,b2,c2]=time-1
heapq.heappush(Q,(time-1,a2,b2,c2))
a2,b2,c2=calc_c(a,b,c)
if a2>=0 and b2>=0 and c2>=0:
if (a2,b2,c2) in DP:
if DP[(a2,b2,c2)]>time-1:
DP[a2,b2,c2]=time-1
heapq.heappush(Q,(time-1,a2,b2,c2))
else:
DP[a2,b2,c2]=time-1
heapq.heappush(Q,(time-1,a2,b2,c2))
print(-min(DP.values()))
titia