結果

問題 No.966 引き算をして門松列(その1)
ユーザー はむ吉🐹はむ吉🐹
提出日時 2020-01-13 20:49:45
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 1,262 bytes
コンパイル時間 99 ms
コンパイル使用メモリ 10,976 KB
実行使用メモリ 8,408 KB
最終ジャッジ日時 2023-08-23 13:28:05
合計ジャッジ時間 846 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,016 KB
testcase_01 AC 16 ms
8,356 KB
testcase_02 AC 16 ms
8,308 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 AC 94 ms
8,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3

INF = 10 ** 9


def is_kado(a, b, c):
    x = sorted((a, b, c))[1]
    return a > 0 and b > 0 and c > 0 and a != b and b != c and c != a and (a == x or c == x)


def minimize_cost_a(a, b, c):
    if is_kado(a, b, c):
        return 0
    if a >= c:
        a, c = c, a
    if c >= b:
        cost = c - (b - 1)
        c = b - 1
    if a >= c:
        cost += a - (c - 1)
        a = c - 1
    if is_kado(a, b, c):
        return cost
    else:
        return None


def minimize_cost_b(a, b, c):
    if is_kado(a, b, c):
        return 0
    if a >= c:
        a, c = c, a
    if b >= a:
        cost = b - (a - 1)
        b = a - 1
    if a == c:
        cost += a - (c - 1)
        a -= 1
    if is_kado(a, b, c):
        return cost
    else:
        return None


def minimize_cost(a, b, c):
    cost_a = minimize_cost_a(a, b, c)
    if cost_a is None:
        cost_a = INF
    cost_b = minimize_cost_b(a, b, c)
    if cost_b is None:
        cost_b = INF
    cost = min(cost_a, cost_b)
    return cost if cost < INF else -1


def main():
    t = int(input())
    for _ in range(t):
        a, b, c = (int(z) for z in input().split())
        cost = minimize_cost(a, b, c)
        print(cost)


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