結果

問題 No.967 引き算をして門松列(その2)
ユーザー 👑 tamatotamato
提出日時 2020-01-13 21:35:42
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 180 ms / 2,000 ms
コード長 1,182 bytes
コンパイル時間 289 ms
コンパイル使用メモリ 87,088 KB
実行使用メモリ 78,604 KB
最終ジャッジ日時 2023-08-24 15:32:53
合計ジャッジ時間 2,626 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,492 KB
testcase_01 AC 70 ms
71,536 KB
testcase_02 AC 71 ms
71,332 KB
testcase_03 AC 126 ms
78,004 KB
testcase_04 AC 130 ms
78,184 KB
testcase_05 AC 130 ms
78,272 KB
testcase_06 AC 129 ms
77,856 KB
testcase_07 AC 131 ms
78,052 KB
testcase_08 AC 161 ms
78,604 KB
testcase_09 AC 166 ms
78,348 KB
testcase_10 AC 158 ms
78,512 KB
testcase_11 AC 180 ms
78,492 KB
権限があれば一括ダウンロードができます

ソースコード

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
        if B <= 2:
            ans1 = 10**30
        else:
            ans1 = 0
            a = A
            b = B
            c = C
            if a >= b:
                ans1 += x * (a - (b-1))
                a = b-1
            if c >= b:
                ans1 += z * (c - (b-1))
                c = b-1
            if a == c:
                ans1 += min(x, z)

        # b min
        if A == 1 or C == 1 or A == C == 2:
            ans2 = 10**30
        else:
            ans2 = 0
            a = A
            b = B
            c = C
            if a == c:
                if x < z:
                    ans2 += x
                    a -= 1
                else:
                    ans2 += z
                    c -= 1
            ans2 += y * max(b - (min(a, c) - 1), 0)
        ans = min(ans1, ans2)
        if ans == 10**30:
            print(-1)
        else:
            print(ans)


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