結果

問題 No.158 奇妙なお使い
ユーザー yaoshimax
提出日時 2015-03-01 14:39:22
言語 PyPy2
(7.3.15)
結果
WA  
実行時間 -
コード長 1,617 bytes
コンパイル時間 627 ms
コンパイル使用メモリ 76,576 KB
実行使用メモリ 188,784 KB
最終ジャッジ日時 2024-06-24 00:31:54
合計ジャッジ時間 13,932 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 20 WA * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

from Queue import Queue
A1000,A100,A1=map(int,raw_input().split())
Db =int(raw_input())
B1000,B100,B1=map(int,raw_input().split())
Dc = int(raw_input())
C1000,C100,C1=map(int,raw_input().split())

dp = [[[-1 for i in xrange(10001)] for j in xrange(101)] for k in xrange(11)]
best = [(-1,-1,-1) for i in xrange(10001)]
q = Queue()
dp[A1000][A100][A1]=0
ans = 0
q.put((0,A1000,A100,A1))
while q.empty()==False:
    dist,At,Ah,Ao = q.get()
    ans = max(ans,dist)
    price = At*1000+Ah*100+Ao*1
    bt,bh,bo=best[price]
    if bt != -1 and ((bt==At and bh >= Ah) or (bh==Ah and bt>At) or (bo==Ao and bt>At)) :
        continue
    for at in range(min(At,Db/1000)+1):
        for ah in range( max(0,(Db-at*1000-Ao+99)/100), min(Ah,max(0,(Db-at*1000)/100))+1):
            ao=Db-at*1000-ah*100
            if at > At or ah > Ah or ao > Ao:
                print at,At,ah,Ah,ao,Ao
            #print "see",At-at+B1000,Ah-ah+B100,Ao-ao+B1
            if dp[At-at+B1000][Ah-ah+B100][Ao-ao+B1]==-1:
                dp[At-at+B1000][Ah-ah+B100][Ao-ao+B1]=dist+1
                q.put((dist+1,At-at+B1000,Ah-ah+B100,Ao-ao+B1))
    for at in range(min(At,Dc/1000)+1):
        for ah in range( max(0,(Dc-at*1000-Ao+99)/100), min(Ah,max(0,(Dc-at*1000)/100))+1):
            ao=Dc-at*1000-ah*100
            if at > At or ah > Ah or ao > Ao:
                print at,At,ah,Ah,ao,Ao
            #print "see",At-at+C1000,Ah-ah+C100,Ao-ao+C1
            if dp[At-at+C1000][Ah-ah+C100][Ao-ao+C1]==-1:
                dp[At-at+C1000][Ah-ah+C100][Ao-ao+C1]=dist+1
                q.put((dist+1,At-at+C1000,Ah-ah+C100,Ao-ao+C1))
print ans
0