結果

問題 No.158 奇妙なお使い
ユーザー titiatitia
提出日時 2022-03-28 04:43:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,164 ms / 5,000 ms
コード長 1,766 bytes
コンパイル時間 336 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 230,224 KB
最終ジャッジ日時 2024-04-24 12:51:42
合計ジャッジ時間 4,167 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
58,112 KB
testcase_01 AC 65 ms
67,840 KB
testcase_02 AC 44 ms
58,240 KB
testcase_03 AC 38 ms
52,864 KB
testcase_04 AC 1,164 ms
230,224 KB
testcase_05 AC 34 ms
52,480 KB
testcase_06 AC 35 ms
52,864 KB
testcase_07 AC 36 ms
53,120 KB
testcase_08 AC 36 ms
52,864 KB
testcase_09 AC 36 ms
52,992 KB
testcase_10 AC 50 ms
64,000 KB
testcase_11 AC 46 ms
62,080 KB
testcase_12 AC 37 ms
53,120 KB
testcase_13 AC 35 ms
53,248 KB
testcase_14 AC 52 ms
66,560 KB
testcase_15 AC 100 ms
78,544 KB
testcase_16 AC 44 ms
59,520 KB
testcase_17 AC 168 ms
80,344 KB
testcase_18 AC 217 ms
93,920 KB
testcase_19 AC 45 ms
58,496 KB
testcase_20 AC 55 ms
64,896 KB
testcase_21 AC 108 ms
78,336 KB
testcase_22 AC 93 ms
78,340 KB
testcase_23 AC 45 ms
58,880 KB
testcase_24 AC 43 ms
58,368 KB
testcase_25 AC 37 ms
52,480 KB
testcase_26 AC 54 ms
63,872 KB
testcase_27 AC 37 ms
52,864 KB
testcase_28 AC 96 ms
77,312 KB
testcase_29 AC 41 ms
60,672 KB
testcase_30 AC 121 ms
79,020 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# ダイクストラ
# どういう順番にダイクストラすれば良いかで戸惑ったけれど、
# 制約が金額にあるので、金額が大きい順に見るのが正しかった

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

def SUM(x,y,z):
    return x*1000+y*100+z

Q=[]
Q.append((-SUM(A[0],A[1],A[2]),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:
    S,a,b,c=heapq.heappop(Q)
    time=DP[a,b,c]

    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,(-SUM(a2,b2,c2),a2,b2,c2))
                
        else:
            DP[a2,b2,c2]=time+1
            heapq.heappush(Q,(-SUM(a2,b2,c2),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,(-SUM(a2,b2,c2),a2,b2,c2))
        else:
            DP[a2,b2,c2]=time+1
            heapq.heappush(Q,(-SUM(a2,b2,c2),a2,b2,c2))

print(max(DP.values())) 
0