結果

問題 No.966 引き算をして門松列(その1)
ユーザー brthyyjpbrthyyjp
提出日時 2020-04-16 17:56:31
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,340 bytes
コンパイル時間 205 ms
コンパイル使用メモリ 82,256 KB
実行使用メモリ 78,564 KB
最終ジャッジ日時 2024-04-09 21:24:45
合計ジャッジ時間 1,263 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
52,620 KB
testcase_01 AC 31 ms
53,908 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 136 ms
77,712 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

t = int(input())
for i in range(t):
    a, b, c = map(int, input().split())
    l = [a, b, c]
    if len(set(l)) == 1:
        if a == 1 or a == 2:
            print(-1)
        else:
            print(3)
    else:
        l.sort(reverse=True)
        if a == l[0] and b == l[1] and c == l[2]:
            ans1 = a-b+1
            if b-1 == c:
                if c == 1:
                    ans1 = -1
                else:
                    ans1 += 1
            ans2 = b-c+1
            if c == 1:
                ans2 = -1
            if ans1 == -1 and ans2 == -1:
                print(-1)
            else:
                print(min(ans1, ans2))
        elif a == l[0] and b == l[2] and c == l[1]:
            print(0)
        elif a == l[1] and b == l[0] and c == l[2]:
            print(0)
        elif a == l[1] and b == l[2] and c == l[0]:
            print(0)
        elif a == l[2] and b == l[0] and c == l[1]:
            print(0)
        else:
            a, c = c, a
            ans1 = a-b+1
            if b-1 == c:
                if c == 1:
                    ans1 = -1
                else:
                    ans1 += 1
            ans2 = b-c+1
            if c == 1:
                ans2 = -1
            if ans1 == -1 and ans2 == -1:
                print(-1)
            else:
                print(min(ans1, ans2))
0