結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,836 KB
testcase_01 AC 17 ms
7,940 KB
testcase_02 AC 16 ms
7,940 KB
testcase_03 AC 16 ms
7,884 KB
testcase_04 AC 30 ms
9,076 KB
testcase_05 AC 32 ms
9,520 KB
testcase_06 AC 39 ms
10,020 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

T = int(readline())
m = map(int,read().split())
ABC = zip(m,m,m)

INF = 10 ** 18

def type_231(A,B,C):
    a = B - 1
    if a > A:
        a = A
    c = a - 1
    if c > C:
        c = C
    if c <= 0:
        return INF
    return (A - a) + (C - c)

def type_213(A,B,C):
    a = C - 1
    if a > A:
        a = A
    b = a - 1
    if b > B:
        b = B
    if b <= 0:
        return INF
    return (A - a) + (B - b)

def solve(A,B,C):
    x = min(type_231(A,B,C), type_231(C,B,A), type_213(A,B,C), type_213(C,B,A))
    return x if x < INF else -1

answer = [solve(a,b,c) for a,b,c in ABC]
print('\n'.join(map(str,answer)))
0