結果

問題 No.966 引き算をして門松列(その1)
ユーザー ThetaTheta
提出日時 2022-11-22 15:36:22
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 1,390 bytes
コンパイル時間 136 ms
コンパイル使用メモリ 11,940 KB
実行使用メモリ 10,160 KB
最終ジャッジ日時 2023-10-24 07:48:56
合計ジャッジ時間 1,188 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
10,144 KB
testcase_01 AC 32 ms
10,144 KB
testcase_02 AC 30 ms
10,144 KB
testcase_03 AC 30 ms
10,144 KB
testcase_04 AC 77 ms
10,160 KB
testcase_05 AC 80 ms
10,160 KB
testcase_06 AC 93 ms
10,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    for _ in range(int(input())):
        A, B, C = map(int, input().split())
        if A > C:
            A, C = C, A
        if [A, B, C].count(1) >= 2:
            print(-1)
            continue

        if B > A and B > C:
            if A == C:
                if A == 1:
                    print(-1)
                else:
                    print(1)
            else:
                print(0)
            continue

        if B < A and B < C:
            if A != C:
                print(0)
            elif A - B >= 2:
                print(1)
            elif B == 1:
                print(-1)
            else:
                print(2)
            continue

        if A == B:
            if B == C:
                if B <= 2:
                    print(-1)
                else:
                    print(3)
            else:
                print(1)
            continue

        if B == C:
            if (C-A) >= 2:
                print(1)
            elif A >= 2:
                print(2)
            else:
                print(-1)
            continue

        if A < B:
            if A == 1:
                if B == 2:
                    print(-1)
                else:
                    print(C-B+1)
            elif (B-A) == 1:
                print(2)
            else:
                print(min(B-A+1, C-B+1))


if __name__ == "__main__":
    main()
0