結果

問題 No.966 引き算をして門松列(その1)
ユーザー kimiyukikimiyuki
提出日時 2020-01-13 21:02:28
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 807 bytes
コンパイル時間 569 ms
コンパイル使用メモリ 10,892 KB
実行使用メモリ 8,460 KB
最終ジャッジ日時 2023-08-24 13:28:56
合計ジャッジ時間 6,625 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,032 KB
testcase_01 AC 17 ms
8,032 KB
testcase_02 AC 17 ms
8,084 KB
testcase_03 AC 21 ms
8,032 KB
testcase_04 AC 1,449 ms
8,460 KB
testcase_05 AC 1,680 ms
8,004 KB
testcase_06 TLE -
権限があれば一括ダウンロードができます

ソースコード

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):
    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, a - a1 + b - b1 + c - c1)
    if math.isinf(ans):
        return -1
    return ans

for _ in range(int(input())):
    a, b, c = map(int, input().split())
    print(solve(a, b, c))
0