結果

問題 No.158 奇妙なお使い
ユーザー titiatitia
提出日時 2022-03-28 04:42:20
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 2,378 ms / 5,000 ms
コード長 1,570 bytes
コンパイル時間 85 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 86,928 KB
最終ジャッジ日時 2024-04-24 12:50:57
合計ジャッジ時間 4,844 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
11,008 KB
testcase_01 AC 33 ms
11,136 KB
testcase_02 AC 31 ms
10,880 KB
testcase_03 AC 30 ms
11,008 KB
testcase_04 AC 2,378 ms
86,928 KB
testcase_05 AC 28 ms
10,880 KB
testcase_06 AC 28 ms
10,880 KB
testcase_07 AC 27 ms
11,008 KB
testcase_08 AC 26 ms
10,880 KB
testcase_09 AC 27 ms
10,880 KB
testcase_10 AC 31 ms
10,880 KB
testcase_11 AC 31 ms
10,880 KB
testcase_12 AC 28 ms
10,880 KB
testcase_13 AC 27 ms
11,008 KB
testcase_14 AC 31 ms
11,008 KB
testcase_15 AC 41 ms
11,264 KB
testcase_16 AC 31 ms
10,880 KB
testcase_17 AC 67 ms
11,904 KB
testcase_18 AC 342 ms
20,912 KB
testcase_19 AC 29 ms
11,008 KB
testcase_20 AC 32 ms
11,136 KB
testcase_21 AC 122 ms
12,544 KB
testcase_22 AC 120 ms
12,288 KB
testcase_23 AC 29 ms
10,880 KB
testcase_24 AC 29 ms
10,880 KB
testcase_25 AC 28 ms
11,008 KB
testcase_26 AC 31 ms
10,880 KB
testcase_27 AC 29 ms
10,880 KB
testcase_28 AC 37 ms
11,136 KB
testcase_29 AC 29 ms
11,008 KB
testcase_30 AC 54 ms
12,160 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