結果

問題 No.966 引き算をして門松列(その1)
ユーザー tails1434tails1434
提出日時 2020-01-14 21:21:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 177 ms / 2,000 ms
コード長 1,115 bytes
コンパイル時間 1,221 ms
コンパイル使用メモリ 86,364 KB
実行使用メモリ 78,676 KB
最終ジャッジ日時 2023-08-27 03:41:55
合計ジャッジ時間 1,780 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,204 KB
testcase_01 AC 72 ms
71,084 KB
testcase_02 AC 70 ms
71,136 KB
testcase_03 AC 72 ms
70,808 KB
testcase_04 AC 177 ms
78,184 KB
testcase_05 AC 174 ms
78,676 KB
testcase_06 AC 170 ms
78,044 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
def main():
    T = int(input())
    for _ in range(T):
        ans = 0
    
        A, B, C = map(int, input().split())
        if A == C == 1:
            print(-1)
            continue

        if B <= 2:
            max_cost = float('inf')
        else:
            max_cost = 0
            a = int(A)
            b = int(B)
            c = int(C)
            if a >= b:
                max_cost += a - (b - 1)
                a = b - 1
            if c >= b:
                max_cost += c - (b - 1)
                c = b - 1
            if a == c:
                max_cost += 1

        if A == 1 or C == 1 or A == C == 2:
            min_cost = float('inf')
        else:
            a = int(A)
            b = int(B)
            c = int(C)
            min_cost = 0
            if a == c:
                min_cost += 1
                c -= 1
            min_cost += max(b - (min(a,c) - 1),0)

        ans = min(max_cost, min_cost)
        if ans == float('inf'):
            print(-1)
        else:
            print(ans)

        


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