結果

問題 No.966 引き算をして門松列(その1)
ユーザー uni_pythonuni_python
提出日時 2020-10-01 23:09:58
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 146 ms / 2,000 ms
コード長 1,348 bytes
コンパイル時間 254 ms
コンパイル使用メモリ 87,148 KB
実行使用メモリ 79,248 KB
最終ジャッジ日時 2023-09-21 12:33:11
合計ジャッジ時間 1,628 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,208 KB
testcase_01 AC 67 ms
71,212 KB
testcase_02 AC 67 ms
71,344 KB
testcase_03 AC 68 ms
71,508 KB
testcase_04 AC 146 ms
79,248 KB
testcase_05 AC 132 ms
78,524 KB
testcase_06 AC 139 ms
78,216 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    T=I()
    inf=10**10
    for _ in range(T):
        ans=inf
        a,b,c=MI()
        L=[a,b,c]
        
        # bが最大かつa,cが等しくない
        t=b-1
        temp=0
        if a>t:
            temp+=a-t
            a=t
        if c>t:        
            temp+=c-t
            c=t
        if a==c:
            a-=1
            temp+=1
        if a>=1:
            ans=min(ans,temp)
            
        # print(a,b,c,temp)
        a,b,c=L
            
        # bが最小かつa,cが等しくない
        t=min(L)
        temp=b-t
        b=t
        if a==b==c:
            b-=2
            a-=1
            temp+=3
        
        elif a==b:
            b-=1
            temp+=1
        elif b==c:
            b-=1
            temp+=1
        elif a==c:
            a-=1
            temp+=1
            if a==b:
                b-=1
                temp+=1
        if b>=1:
            ans=min(ans,temp)
            
        # print(a,b,c,temp)
            
                
        if ans==inf:
            print(-1)
        else:
            print(ans)
            
        
        
        
            
        
        


main()
0