結果

問題 No.967 引き算をして門松列(その2)
ユーザー titiatitia
提出日時 2020-01-13 21:32:22
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 118 ms / 2,000 ms
コード長 1,391 bytes
コンパイル時間 443 ms
コンパイル使用メモリ 10,896 KB
実行使用メモリ 8,268 KB
最終ジャッジ日時 2023-08-24 15:21:41
合計ジャッジ時間 1,798 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,044 KB
testcase_01 AC 16 ms
8,268 KB
testcase_02 AC 16 ms
8,008 KB
testcase_03 AC 55 ms
8,232 KB
testcase_04 AC 58 ms
8,144 KB
testcase_05 AC 59 ms
8,052 KB
testcase_06 AC 59 ms
8,012 KB
testcase_07 AC 59 ms
8,092 KB
testcase_08 AC 85 ms
8,080 KB
testcase_09 AC 118 ms
8,144 KB
testcase_10 AC 111 ms
8,048 KB
testcase_11 AC 112 ms
8,036 KB
権限があれば一括ダウンロードができます

ソースコード

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())

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

    if A==B==C:
        if A>=3:
            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 B>=2:
            print(min(Y+X,Y+Z,2*X+3*Z,2*Z+3*X))
        else:
            print(-1)
        continue

    ANS=1<<60
    if A>=B and check(B-1,B,C)==1:
        ANS=min(ANS,(A-(B-1))*X)

    if A>=C and check(C-1,B,C)==1:
        ANS=min(ANS,(A-(C-1))*X)

    if B>=A and check(A,A-1,C)==1:
        ANS=min(ANS,(B-(A-1))*Y)

    if B>=C and check(A,C-1,C)==1:
        ANS=min(ANS,(B-(C-1))*Y)

    if C>=A and check(A,B,A-1)==1:
        ANS=min(ANS,(C-(A-1))*Z)

    if C>=B and check(A,B,B-1)==1:
        ANS=min(ANS,(C-(B-1))*Z)


    if A>=B>C and C>1 and C==B-1:
        ANS=min(ANS,X*(A-(B-1))+Z)

    if C>=B>A and A>1 and A==B-1:
        ANS=min(ANS,Z*(C-(B-1))+X)

    if A>B==C and B>2:
        ANS=min(ANS,X*(A-(B-1))+Z+min(X,Z))

    if C>B==A and B>2:
        ANS=min(ANS,Z*(C-(B-1))+X+min(X,Z))
        
        

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

0