結果

問題 No.967 引き算をして門松列(その2)
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2020-01-13 21:28:43
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 2,036 bytes
コンパイル時間 153 ms
コンパイル使用メモリ 10,860 KB
実行使用メモリ 8,276 KB
最終ジャッジ日時 2023-08-24 15:02:56
合計ジャッジ時間 1,625 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,044 KB
testcase_01 AC 17 ms
8,128 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())

for i in range(T):

    A,B,C,X,Y,Z= map(int,input().split())
    

    if A==B and B==C:

        if A < 3:
            print (-1)
        else:
            print (min(X+Z*2,X*2+Z,Y*2+X,Y*2+Z))

    elif A==B or B==C:
        if B == 1:
            print (-1)
        elif abs(A-C) == 1: #1 2 2 or 2 2 3

            #A=Bにする
            if B==C:
                t = C
                C = A
                A = t
                s = X
                X = Z
                Z = s
            
            
            if min(A,B,C) == 1:
                print (-1)
            elif min(A,B,C) < B: #3 3 2 / 5 5 4など
                if C > 1:
                    print (min(X*2,Y*2,X+Z))
            else: #5 5 6/ 3 3 4など
                print (min(X,Y))

        else: #9 9 3/2 2 5など

            #A=Bにする
            if B==C:
                t = C
                C = A
                A = t
                s = X
                X = Z
                Z = s

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

    else: #9 2 1

        ans = float("inf")

        if min(A,B,C) == B or max(A,B,C) == B:
            print (0)
        else:
            ans = float("inf")

            if A < C: #A>B>Cにする
                t = C
                C = A
                A = t
                s = X
                X = Z
                Z = s
            
            na = B-1

            if na != C and na > 0:
                ans = min(ans,(A-na)*X)

            nb = C-1
            if nb > 0:
                ans = min(ans,(B-nb)*Y)

            if ans == float("inf"):
                print (-1)
            else:
                print (ans)
        
0