結果

問題 No.968 引き算をして門松列(その3)
ユーザー convexineqconvexineq
提出日時 2021-04-11 02:58:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 257 ms / 2,000 ms
コード長 654 bytes
コンパイル時間 948 ms
コンパイル使用メモリ 86,636 KB
実行使用メモリ 80,288 KB
最終ジャッジ日時 2023-09-09 06:32:31
合計ジャッジ時間 3,990 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,544 KB
testcase_01 AC 73 ms
71,304 KB
testcase_02 AC 73 ms
71,352 KB
testcase_03 AC 196 ms
78,908 KB
testcase_04 AC 177 ms
79,288 KB
testcase_05 AC 172 ms
79,120 KB
testcase_06 AC 175 ms
79,120 KB
testcase_07 AC 172 ms
78,860 KB
testcase_08 AC 221 ms
79,776 KB
testcase_09 AC 250 ms
79,848 KB
testcase_10 AC 250 ms
80,288 KB
testcase_11 AC 257 ms
79,756 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def bmin(a,b,c,x,y,z):
    Y,X = max(0,b+1-a), max(0,b+1-c)
    r = y*Y + x*X
    a -= X
    c -= Y
    b -= X+Y
    if a == c:
        a -= 1
        b -= 1
        r += min(x,y)
    if a <= 0 or b <= 0 or c <= 0: return INF
    return r

def bmax(a,b,c,x,y,z):
    r = 0
    if a==c:
        a -= 1
        b -= 1
        r += min(x,y)
    v = max(b,max(a,c)+1)-b
    a -= v
    c -= v
    if a <= 0 or b <= 0 or c <= 0: return INF
    return r+v*z


INF = 4*10**18
T = int(input())
for _ in range(T):
    a,b,c,x,y,z = map(int,input().split())
    p = bmin(a,b,c,x,y,z)
    q = bmax(a,b,c,x,y,z)
    ans = min(p,q)
    print(-1 if ans == INF else ans)
0