結果

問題 No.968 引き算をして門松列(その3)
ユーザー tamatotamato
提出日時 2020-01-13 21:57:27
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,884 bytes
コンパイル時間 1,062 ms
コンパイル使用メモリ 87,028 KB
実行使用メモリ 79,336 KB
最終ジャッジ日時 2023-08-24 16:28:53
合計ジャッジ時間 3,248 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,124 KB
testcase_01 AC 72 ms
71,096 KB
testcase_02 AC 72 ms
71,080 KB
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 #

def main():
    import sys
    input = sys.stdin.readline

    T = int(input())
    for _ in range(T):
        A, B, C, x, y, z = map(int, input().split())

        if A == C == 1:
            print(-1)
            continue

        # b max
        a, b, c = A, B, C
        ans1 = 0
        if a >= b:
            d = a - (b-1)
            ans1 += z * d
            a -= d
            c -= d
        if c >= b:
            d = c - (b-1)
            ans1 += z * d
            a -= d
            c -= d
        if a == c:
            ans11 = ans1
            a1, b1, c1 = a, b, c
            ans11 += x
            a1 -= 1
            b1 -= 1
            if b1 == c1:
                ans11 += z
                a1 -= 1
                c1 -= 1
            if a1 <= 0 or b1 <= 0 or c1 <= 0:
                ans11 = 10**30
            ans12 = ans1
            a2, b2, c2 = a, b, c
            ans12 += y
            c2 -= 1
            b2 -= 1
            if b2 == a2:
                ans12 += z
                a2 -= 1
                c2 -= 1
            if a2 <= 0 or b2 <= 0 or c2 <= 0:
                ans12 = 10 ** 30
            ans1 = min(ans11, ans12)
        else:
            if a <= 0 or b <= 0 or c <= 0:
                ans1 = 10**30

        # b min
        a, b, c = A, B, C
        ans2 = 0
        if a <= b:
            d = b - (a-1)
            ans2 += y * d
            b -= d
            c -= d
        if c <= b:
            d = b - (c-1)
            ans2 = x * d
            a -= d
            b -= d
        if a == c:
            ans2 += min(x, y)
            b -= 1
            if b <= 0:
                ans2 = 10**30
        else:
            if a <= 0 or b <= 0 or c <= 0:
                ans2 = 10**30

        ans = min(ans1, ans2)
        if ans != 10**30:
            print(ans)
        else:
            print(-1)


if __name__ == '__main__':
    main()
0