結果

問題 No.966 引き算をして門松列(その1)
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2020-01-13 20:56:29
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 92 ms / 2,000 ms
コード長 1,252 bytes
コンパイル時間 88 ms
コンパイル使用メモリ 10,740 KB
実行使用メモリ 8,368 KB
最終ジャッジ日時 2023-08-23 13:42:20
合計ジャッジ時間 1,029 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,324 KB
testcase_01 AC 17 ms
7,852 KB
testcase_02 AC 16 ms
8,328 KB
testcase_03 AC 17 ms
8,308 KB
testcase_04 AC 73 ms
8,368 KB
testcase_05 AC 76 ms
7,864 KB
testcase_06 AC 92 ms
8,240 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

T = int(input())

for i in range(T):

    A,B,C = map(int,input().split())

    if A==B and B==C:

        if A < 3:
            print (-1)
        else:
            print (3)

    elif A==B or B==C:
        if B == 1:
            print (-1)
        elif abs(A-C) == 1: #1 2 2 or 2 2 3
            if min(A,B,C) == 1:
                print (-1)
            elif min(A,B,C) < B:
                print (2)
            else:
                print (1)

        else: #3 9 9
            print (1)
            
    elif A == C:
        if A != 1 and B != A-1:
            print (1)
        elif A != 1 and B == A-1 and A-2 > 0:
            print (2)
        else:
            print (-1)

    else: #9 2 1

        ans = float("inf")

        if min(A,B,C) == B or max(A,B,C) == B:
            print (0)
        else:
            ans = float("inf")

            if A < C:
                t = C
                C = A
                A = t

            na = B-1

            if na != C and na > 0:
                ans = min(ans,A-na)

            nb = C-1
            if nb > 0:
                ans = min(ans,B-nb)

            if ans == float("inf"):
                print (-1)
            else:
                print (ans)
        
            
            
0