結果

問題 No.968 引き算をして門松列(その3)
ユーザー titiatitia
提出日時 2020-01-13 21:56:59
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,530 bytes
コンパイル時間 219 ms
コンパイル使用メモリ 10,860 KB
実行使用メモリ 8,252 KB
最終ジャッジ日時 2023-08-24 16:28:08
合計ジャッジ時間 5,278 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,120 KB
testcase_01 AC 16 ms
8,180 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

T=int(input())

def check(A,B,C):
    if min(A,B,C)<=0:
        return 0
    if A==B or B==C or C==A:
        return 0
    if B==max(A,B,C) or B==min(A,B,C):
        return 1
    return 0

    

for test in range(T):
    A,B,C,X,Y,Z=map(int,input().split())
    Y,Z=Z,Y

    if check(A,B,C)==1:
        print(0)
        continue

    if A==B==C:
        if A>=4:
            print(min(X+2*Z,Z+2*X,2*Y+X,2*Y+Z))
        else:
            print(-1)
        continue

    if A==C and B==A+1:
        if A>=5:
            print(min(Y+X,Y+Z,2*X+3*Z,2*Z+3*X))
        elif A>=3:
            print(min(Y+X,Y+Z))
            
        else:
            print(-1)
        continue

    ANS=1<<60
    
    LA=[0,1]
    LB=[0,1]
    LC=[0,1]

    if B-C>=0:
        LA.append(B-C)
        LA.append(B-C+1)
        LA.append(B-C+2)

    if A-C>=0:
        LA.append(A-C)
        LA.append(A-C+1)
        LA.append(A-C+2)

    if A-B>=0:
        LB.append(A-B)
        LB.append(A-B+1)
        LB.append(A-B+2)

    if C-B>=0:
        LB.append(C-B)
        LB.append(C-B+1)
        LB.append(C-B+2)
        
    if B-A>=0:
        LC.append(B-A)
        LC.append(B-A+1)
        LC.append(B-A+2)

    if C-A>=0:
        LC.append(C-A)
        LC.append(C-A+1)
        LC.append(C-A+2)

    for la in LA:
        for lb in LB:
            for lc in LC:
                if check(A-la-lc,B-la-lb,C-lb-lc)==1:
                    ANS=min(ANS,la*X+lb*Y+lc*Z)                

    if ANS==1<<60:
        print(-1)
    else:
        print(ANS)
    

0