結果

問題 No.966 引き算をして門松列(その1)
コンテスト
ユーザー koheijkt
提出日時 2026-03-07 09:37:14
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 912 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 172 ms
コンパイル使用メモリ 85,596 KB
実行使用メモリ 81,936 KB
最終ジャッジ日時 2026-03-07 09:37:15
合計ジャッジ時間 1,013 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 5
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

INF = 1e18
T = int(input())
ansl = []
for i in range(T):
    cost = INF
    a, b, c = map(int, input().split())
    candi = []

    if a == c == b + 1 and b >= 2:
        ansl.append(2)
        continue

    # b をminにする
    m = min(a, c)

    if a == c:
        if a > b + 1:
            cost1 = max(0, b - (m - 2)) + 1
            if m - 2 > 0:
                candi.append(cost1)
    else:
        cost2 = max(0, b - (m - 1))
        if m - 1 > 0:
            candi.append(cost2)

    # b をmaxにする
    if b >= 3 and not(a == c == 1):
        cost3 = 0
        if a >= b - 1:
            cost3 += a - (b - 1)
            a = b - 1
        if c >= b - 1:
            cost3 += c - (b - 1)
            c = b - 1
        if a == c:
            cost3 += 1

        candi.append(cost3)

    if candi:
        ans = min(candi)
    else:
        ans = -1
    
    ansl.append(ans)

print(*ansl, sep='\n')
0