結果

問題 No.967 引き算をして門松列(その2)
ユーザー kurimupykurimupy
提出日時 2020-06-18 12:19:30
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 105 ms / 2,000 ms
コード長 2,685 bytes
コンパイル時間 91 ms
コンパイル使用メモリ 11,224 KB
実行使用メモリ 8,480 KB
最終ジャッジ日時 2023-09-16 12:00:58
合計ジャッジ時間 1,948 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,480 KB
testcase_01 AC 16 ms
8,440 KB
testcase_02 AC 16 ms
8,440 KB
testcase_03 AC 51 ms
8,404 KB
testcase_04 AC 51 ms
8,400 KB
testcase_05 AC 52 ms
8,440 KB
testcase_06 AC 52 ms
8,452 KB
testcase_07 AC 53 ms
8,460 KB
testcase_08 AC 75 ms
8,388 KB
testcase_09 AC 105 ms
8,064 KB
testcase_10 AC 105 ms
8,452 KB
testcase_11 AC 105 ms
8,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#別アカウント分統合
T = int(input())


def case_1(A,B,C,X,Y,Z):
    a,b,c,x,y,z=A,B,C,X,Y,Z
    cost = 0
    if b > a:
        if b == 1:
            return float("inf")
        else:
            pass
    elif b <= a:
        if b == 1:
            return float("inf")
        elif b > 1:
            cost += x*(a+1-b)
            a = b-1
    # a>c>0 の比較
    if a > c:
        if a == 1:
            return float("inf")
        else:
            pass
    elif a <= c:
        if a == 1:
            return float("inf")
        else:
            cost += z*(c+1-a)
    return cost


def case_2(A,B,C,X,Y,Z):
    a,b,c,x,y,z=A,B,C,X,Y,Z
    cost = 0
    if c > a:
        if c == 1:
            return float("inf")
        else:
            pass
    elif c <= a:
        if c == 1:
            return float("inf")
        elif c > 1:
            cost += x*(a+1-c)
            a = c-1
    # a>b>0 の比較
    if a > b:
        if a == 1:
            return float("inf")
        else:
            pass
    elif a <= b:
        if a == 1:
            return float("inf")
        else:
            cost += y*(b+1-a)
    return cost


def case_3(A,B,C,X,Y,Z):
    a,b,c,x,y,z=A,B,C,X,Y,Z
    cost = 0
    if b > c:
        if b == 1:
            return float("inf")
        else:
            pass
    elif b <= c:
        if b == 1:
            return float("inf")
        elif b > 1:
            cost += z*(c+1-b)
            c = b-1
    # c>a>0 の比較
    if c > a:
        if c == 1:
            return float("inf")
        else:
            pass
    elif c <= a:
        if c == 1:
            return float("inf")
        else:
            cost += x*(a+1-c)
    return cost


def case_4(A,B,C,X,Y,Z):
    a,b,c,x,y,z=A,B,C,X,Y,Z
    cost = 0
    if a > c:
        if a == 1:
            return float("inf")
        else:
            pass
    elif a <= c:
        if a == 1:
            return float("inf")
        elif a > 1:
            cost += z*(c+1-a)
            c = a-1
    # c>b>0 の比較
    if c > b:
        if c == 1:
            return float("inf")
        else:
            pass
    elif c <= b:
        if c == 1:
            return float("inf")
        else:
            cost += y*(b+1-c)
    return cost


def solve():
    ans = float("inf")
    a, b, c, x, y, z = map(int, input().split())
    # case b>a>c>0:
    ans = min(ans, case_1(a, b, c, x, y, z))
    # case c>a>b>0:
    ans = min(ans, case_2(a, b, c, x, y, z))
    # case b>c>a>0:
    ans = min(ans, case_3(a, b, c, x, y, z))
    # case a>c>b>0:
    ans = min(ans, case_4(a, b, c, x, y, z))
    if ans != float("inf"):
        return ans
    return -1


for i in range(T):
    print(solve())
0