結果

問題 No.158 奇妙なお使い
ユーザー titiatitia
提出日時 2022-03-28 04:31:46
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,487 bytes
コンパイル時間 538 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 271,084 KB
最終ジャッジ日時 2024-04-24 12:46:32
合計ジャッジ時間 9,498 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
59,672 KB
testcase_01 AC 52 ms
62,592 KB
testcase_02 AC 47 ms
59,776 KB
testcase_03 AC 45 ms
54,528 KB
testcase_04 AC 697 ms
207,824 KB
testcase_05 AC 37 ms
55,484 KB
testcase_06 AC 37 ms
54,176 KB
testcase_07 AC 38 ms
54,308 KB
testcase_08 AC 41 ms
54,624 KB
testcase_09 AC 39 ms
54,268 KB
testcase_10 AC 42 ms
62,836 KB
testcase_11 AC 41 ms
60,928 KB
testcase_12 AC 36 ms
54,144 KB
testcase_13 AC 36 ms
54,272 KB
testcase_14 AC 45 ms
62,336 KB
testcase_15 AC 76 ms
77,184 KB
testcase_16 AC 42 ms
60,160 KB
testcase_17 AC 320 ms
82,508 KB
testcase_18 AC 140 ms
95,908 KB
testcase_19 AC 41 ms
59,648 KB
testcase_20 AC 207 ms
79,436 KB
testcase_21 TLE -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

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=deque()
Q.append((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=Q.popleft()
    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
                Q.append((time-1,a2,b2,c2))
                
        else:
            DP[a2,b2,c2]=time-1
            Q.append((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
                Q.append((time-1,a2,b2,c2))
        else:
            DP[a2,b2,c2]=time-1
            Q.append((time-1,a2,b2,c2))

print(-min(DP.values())) 
0