結果

問題 No.968 引き算をして門松列(その3)
ユーザー kimiyuki
提出日時 2020-01-13 21:16:37
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,010 bytes
コンパイル時間 303 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 79,360 KB
最終ジャッジ日時 2024-12-22 21:20:56
合計ジャッジ時間 5,216 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 1 WA * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
import math

def iterate(a, b, c):
    for a in range(a, a + 4):
        for b in range(b, b + 4):
            for c in range(c, c + 4):
                yield a, b, c
                yield max(b + 1, a), b, max(b + 2, c)
                yield max(b + 2, a), b, max(b + 1, c)
                yield max(c + 1, a), b, c
                yield a, b, max(a + 1, c)
                yield a, max(a + 1, b), max(a + 2, c)
                yield max(c + 2, b), max(c + 1, b), c

def solve(a, b, c, x, y, z):
    ans = math.inf
    for na, nb, nc in iterate(a, b, c):
        da = na - a
        db = nb - b
        dc = nc - c
        na, nb, nc = a - db - dc, b - dc - da, c - da - db
        if na != nc and ((na < nb and nb > nc) or (na > nb and nb < nc)):
            if na >= 1 and nb >= 1 and nc >= 1:
                ans = min(ans, y * da + z * db + x * dc)
    if math.isinf(ans):
        return -1
    return ans

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