結果

問題 No.967 引き算をして門松列(その2)
ユーザー tanon710tanon710
提出日時 2020-05-04 23:08:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 264 ms / 2,000 ms
コード長 1,128 bytes
コンパイル時間 1,433 ms
コンパイル使用メモリ 86,940 KB
実行使用メモリ 80,296 KB
最終ジャッジ日時 2023-09-07 08:15:10
合計ジャッジ時間 4,469 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,480 KB
testcase_01 AC 74 ms
71,204 KB
testcase_02 AC 71 ms
71,068 KB
testcase_03 AC 190 ms
78,800 KB
testcase_04 AC 169 ms
78,640 KB
testcase_05 AC 170 ms
78,652 KB
testcase_06 AC 170 ms
78,464 KB
testcase_07 AC 173 ms
78,988 KB
testcase_08 AC 218 ms
79,596 KB
testcase_09 AC 232 ms
80,296 KB
testcase_10 AC 237 ms
80,128 KB
testcase_11 AC 264 ms
79,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

q=int(input())
for _ in range(q):
    a,b,c,x,y,z=map(int,input().split())
    ans=10**18
    #a<c<b
    tmp=[a,b,c]
    cost=0
    if tmp[1]<=tmp[2]:
        cost+=(tmp[2]-tmp[1]+1)*z
        tmp[2]=tmp[1]-1
    if tmp[0]>=tmp[2]:
        cost+=(tmp[0]-tmp[2]+1)*x
        tmp[0]=tmp[2]-1
    if tmp[0]>0:
        ans=min(ans,cost)
    #c<a<b
    tmp=[a,b,c]
    cost=0
    if tmp[0]>=tmp[1]:
        cost+=(tmp[0]-tmp[1]+1)*x
        tmp[0]=tmp[1]-1
    if tmp[2]>=tmp[0]:
        cost+=(tmp[2]-tmp[0]+1)*z
        tmp[2]=tmp[0]-1
    if tmp[2]>0:
        ans=min(ans,cost)
    #b<a<c
    tmp=[a,b,c]
    cost=0
    if tmp[0]>=tmp[2]:
        cost+=(tmp[0]-tmp[2]+1)*x
        tmp[0]=tmp[2]-1
    if tmp[1]>=tmp[0]:
        cost+=(tmp[1]-tmp[0]+1)*y
        tmp[1]=tmp[0]-1
    if tmp[1]>0:
        ans=min(ans,cost)
    #b<c<a
    tmp=[a,b,c]
    cost=0
    if tmp[2]>=tmp[0]:
        cost+=(tmp[2]-tmp[0]+1)*z
        tmp[2]=tmp[0]-1
    if tmp[1]>=tmp[2]:
        cost+=(tmp[1]-tmp[2]+1)*y
        tmp[1]=tmp[2]-1
    if tmp[1]>0:
        ans=min(ans,cost)
    if ans==10**18:
        print(-1)
    else:
        print(ans)
0