結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
8,292 KB
testcase_01 AC 17 ms
8,204 KB
testcase_02 AC 17 ms
8,160 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 97 ms
8,396 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
    cost = 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
    cost = 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