結果

問題 No.968 引き算をして門松列(その3)
ユーザー maspymaspy
提出日時 2020-01-13 20:47:20
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 1,105 bytes
コンパイル時間 555 ms
コンパイル使用メモリ 10,896 KB
実行使用メモリ 11,472 KB
最終ジャッジ日時 2023-08-23 13:23:27
合計ジャッジ時間 1,680 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
8,256 KB
testcase_01 AC 15 ms
8,208 KB
testcase_02 AC 15 ms
8,200 KB
testcase_03 AC 27 ms
8,696 KB
testcase_04 AC 28 ms
8,620 KB
testcase_05 AC 29 ms
9,000 KB
testcase_06 AC 29 ms
9,204 KB
testcase_07 AC 31 ms
8,840 KB
testcase_08 AC 43 ms
10,464 KB
testcase_09 AC 54 ms
11,376 KB
testcase_10 AC 55 ms
11,472 KB
testcase_11 AC 54 ms
10,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

# 1つに +1 すると考えてあげればよい。作ってみてマイナスになってたらダメ

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

INF = 10 ** 30

def type_231(A,B,C,X,Y,Z):
    a = C + 1
    if a <= A:
        a = A
    b = a + 1
    if b <= B:
        b = B
    x = a - A # 0,-1,-1
    y = b - B # -1,0,-1
    if any((A - y <= 0, B - x <= 0, C - x - y <= 0)):
        return INF
    return x * X + y * Y

def type_213(A,B,C,X,Y,Z):
    a = B + 1
    if a <= A:
        a = A
    c = a + 1
    if c <= C:
        c = C
    x = a - A # 0,-1,-1
    z = c - C # -1,-1,0
    if any((A - z <= 0, B - x - z <= 0, C - x <= 0)):
        return INF
    return x * X + z * Z

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

answer = [solve(*args) for args in ABCXYZ]
print('\n'.join(map(str,answer)))
0