結果

問題 No.966 引き算をして門松列(その1)
ユーザー GrayCoderGrayCoder
提出日時 2020-01-13 21:53:09
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
WA  
実行時間 -
コード長 1,015 bytes
コンパイル時間 278 ms
コンパイル使用メモリ 10,868 KB
実行使用メモリ 10,788 KB
最終ジャッジ日時 2023-08-24 16:18:29
合計ジャッジ時間 879 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,808 KB
testcase_01 AC 17 ms
7,768 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 42 ms
10,312 KB
testcase_06 AC 47 ms
10,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    T = int(input())
    ABC = [list(map(int, input().split())) for _ in [0] * T]

    for abc in ABC:
        ans = 0
        while 1:
            if abc.count(1) == 2 or max(abc) < 3:
                print(-1)
                break
            if abc[0] != abc[2] and (abc[0] < abc[1] > abc[2] or abc[0] > abc[1] < abc[2]):
                print(ans)
                break
            if abc[0] == abc[2]:
                abc[0] -= 1
                ans += 1
                continue
            center = max(0, abc[1] - min(abc) + 1)
            left = max(0, abc[0] - abc[1] + 1)
            right = max(0, abc[2] - abc[1] + 1)
            if center <= left + right:
                abc[1] -= center
                ans += center
            else:
                abc[0] -= left
                abc[2] -= right
                ans += left + right
            if abc.count(0):
                print(-1)
                break


main()
0