結果

問題 No.968 引き算をして門松列(その3)
ユーザー vwxyz
提出日時 2024-04-21 16:18:31
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 417 ms / 2,000 ms
コード長 646 bytes
コンパイル時間 601 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-10-13 15:15:07
合計ジャッジ時間 4,169 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

import itertools
T=int(input())
inf=1<<60
for t in range(T):
    A,B,C,Z,X,Y=map(int,input().split())
    ans=inf
    for tpl in itertools.permutations(range(3)):
        if tpl[1]==1:
            continue
        ABC=[A,B,C]
        for i,j in zip(tpl,tpl[1:]):
            ABC[j]=max(ABC[j],ABC[i]+1)
        cnt=[a-aa for a,aa in zip(ABC,(A,B,C))]
        ABC=[A,B,C]
        for i in range(3):
            for j in range(3):
                if i==j:
                    continue
                ABC[j]-=cnt[i]
        if min(ABC)>0:
            ans=min(ans,sum(c*x for c,x in zip(cnt,(X,Y,Z))))
    if ans==inf:
        ans=-1
    print(ans)
0