結果

問題 No.967 引き算をして門松列(その2)
ユーザー 👑 rin204rin204
提出日時 2022-02-06 21:08:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 207 ms / 2,000 ms
コード長 639 bytes
コンパイル時間 677 ms
コンパイル使用メモリ 86,728 KB
実行使用メモリ 79,372 KB
最終ジャッジ日時 2023-09-02 07:16:21
合計ジャッジ時間 3,481 ms
ジャッジサーバーID
(参考情報)
judge14 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,156 KB
testcase_01 AC 71 ms
71,156 KB
testcase_02 AC 69 ms
71,300 KB
testcase_03 AC 166 ms
78,384 KB
testcase_04 AC 153 ms
78,316 KB
testcase_05 AC 154 ms
78,148 KB
testcase_06 AC 155 ms
78,120 KB
testcase_07 AC 155 ms
78,120 KB
testcase_08 AC 169 ms
78,416 KB
testcase_09 AC 190 ms
78,512 KB
testcase_10 AC 191 ms
77,956 KB
testcase_11 AC 207 ms
79,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve():
    a, b, c, x, y, z = map(int, input().split())
    abc = [a, b, c]
    xyz = [x, y, z]
    inf = 10 ** 20
    ans = inf
    
    for i1, i2, i3 in [[1, 0, 2], [1, 2, 0], [0, 2, 1], [2, 0, 1]]:
        a, x = abc[i1], xyz[i1]
        b, y = abc[i2], xyz[i2]
        c, z = abc[i3], xyz[i3]
        cost = 0
        if b >= a:
            cost += y * (b - a + 1)
            b = a - 1
        if c >= b:
            cost += z * (c - b + 1)
            c = b - 1
        if c > 0:
            ans = min(ans, cost)
    
    if ans == inf:
        print(-1)
    else:
        print(ans)

for _ in range(int(input())):
    solve()
0