結果

問題 No.967 引き算をして門松列(その2)
ユーザー kimiyuki
提出日時 2020-01-13 21:04:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 551 ms / 2,000 ms
コード長 813 bytes
コンパイル時間 190 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 78,592 KB
最終ジャッジ日時 2024-12-22 20:46:00
合計ジャッジ時間 4,402 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
import math

def iterate(a, b, c):
    for a in range(a - 3, a + 1):
        for b in range(b - 3, b + 1):
            for c in range(c - 3, c + 1):
                yield a, b, c
                yield min(b - 1, a), b, min(b - 2, c)
                yield min(b - 2, a), b, min(b - 1, c)
                yield a, min(a - 1, b), c
                yield a, min(c - 1, b), c

def solve(a, b, c, x, y, z):
    ans = math.inf
    for a1, b1, c1 in iterate(a, b, c):
        if 1 <= a1 and 1 <= b1 and 1 <= c1:
            if a1 != c1 and ((a1 < b1 and b1 > c1) or (a1 > b1 and b1 < c1)):
                ans = min(ans, x * (a - a1) + y * (b - b1) + z * (c - c1))
    if math.isinf(ans):
        return -1
    return ans

for _ in range(int(input())):
    print(solve(*map(int, input().split())))
0