結果

問題 No.966 引き算をして門松列(その1)
ユーザー titiatitia
提出日時 2020-02-05 19:00:27
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 653 bytes
コンパイル時間 200 ms
コンパイル使用メモリ 81,820 KB
実行使用メモリ 162,520 KB
最終ジャッジ日時 2023-10-24 03:27:44
合計ジャッジ時間 7,289 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
64,196 KB
testcase_01 AC 58 ms
68,348 KB
testcase_02 AC 57 ms
68,332 KB
testcase_03 AC 124 ms
76,480 KB
testcase_04 AC 1,960 ms
142,360 KB
testcase_05 AC 1,915 ms
141,484 KB
testcase_06 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

def kado(A,B,C):
    if A>0 and B>0 and C>0 and A!=B and A!=C and B!=C and (max(A,B,C)==B or min(A,B,C)==B):
        return 1
    return 0

T=int(input())
for test in range(T):   
    A,B,C=map(int,input().split())
    S=sorted([A,B,C])
    CAN=[S[2]-S[1],S[2]-S[0],S[1]-S[0],0]
    CAN2=[]
    for i in CAN:
        for j in range(i-1,i+3):
            if j>=0:
                CAN2.append(j)

    from itertools import product

    P=list(product(CAN2,repeat=3))
    ANS=1<<31

    for x,y,z in P:
        if kado(A-x,B-y,C-z)==1:
            ANS=min(ANS,x+y+z)

    if ANS==1<<31:
        print(-1)
    else:
        print(ANS)
            
        
0