結果

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

テストケース

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

ソースコード

diff #

#!/usr/bin/env python3

INF = 10 ** 9


def is_kado(a, b, c):
    try:
        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)
    except Exception:
        print("DAMEDESU")


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