結果

問題 No.966 引き算をして門松列(その1)
ユーザー GrayCoderGrayCoder
提出日時 2020-01-13 22:18:49
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 1,602 bytes
コンパイル時間 258 ms
コンパイル使用メモリ 10,884 KB
実行使用メモリ 10,496 KB
最終ジャッジ日時 2023-08-24 17:15:39
合計ジャッジ時間 1,134 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,300 KB
testcase_01 AC 16 ms
8,176 KB
testcase_02 AC 16 ms
8,296 KB
testcase_03 AC 16 ms
8,364 KB
testcase_04 AC 46 ms
9,600 KB
testcase_05 AC 49 ms
10,468 KB
testcase_06 AC 55 ms
10,496 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]

    def func(abc):
        if abc[0] != abc[2] and (abc[0] < abc[1] > abc[2] or abc[0] > abc[1] < abc[2]):
            return True
        else:
            return False

    for abc_ in ABC:
        case1 = 0
        abc = abc_[:]
        while 1:
            if func(abc):
                break
            if abc.count(1) == 2 or max(abc) < 3:
                case1 = float('inf')
                break
            if abc[0] == abc[2]:
                abc[0] -= 1
                case1 += 1
                continue
            center = max(0, abc[1] - min(abc) + 1)
            abc[1] -= center
            case1 += center
            if abc.count(0):
                case1 = float('inf')
                break

        case2 = 0
        abc = abc_[:]
        while 1:
            if func(abc):
                break
            if abc.count(1) == 2 or max(abc) < 3:
                case2 = float('inf')
                break
            if abc[0] == abc[2]:
                abc[0] -= 1
                case2 += 1
                continue
            left = max(0, abc[0] - abc[1] + 1)
            right = max(0, abc[2] - abc[1] + 1)
            abc[0] -= left
            abc[2] -= right
            case2 += left + right
            if abc.count(0):
                case2 = float('inf')
                break

        if case1 == case2 == float('inf'):
            print(-1)
        else:
            print(min(case1, case2))


main()
0