結果

問題 No.966 引き算をして門松列(その1)
ユーザー titia
提出日時 2020-02-05 19:01:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,115 ms / 2,000 ms
コード長 685 bytes
コンパイル時間 245 ms
コンパイル使用メモリ 82,336 KB
実行使用メモリ 100,012 KB
最終ジャッジ日時 2024-09-22 20:28:14
合計ジャッジ時間 4,193 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from itertools import product

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,i+3):
            if j>=0:
                CAN2.append(j)

    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