結果

問題 No.2006 Decrease All to Zero
ユーザー chineristACchineristAC
提出日時 2022-02-23 02:55:11
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 2,013 bytes
コンパイル時間 336 ms
コンパイル使用メモリ 86,440 KB
実行使用メモリ 82,260 KB
最終ジャッジ日時 2023-08-22 12:38:52
合計ジャッジ時間 6,908 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 116 ms
73,796 KB
testcase_01 AC 118 ms
74,012 KB
testcase_02 RE -
testcase_03 AC 121 ms
73,980 KB
testcase_04 AC 116 ms
73,792 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 AC 167 ms
80,492 KB
testcase_09 AC 155 ms
80,736 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 AC 115 ms
73,928 KB
testcase_19 AC 115 ms
73,876 KB
testcase_20 AC 116 ms
73,744 KB
testcase_21 AC 116 ms
73,668 KB
testcase_22 AC 117 ms
74,076 KB
testcase_23 AC 118 ms
73,844 KB
testcase_24 AC 122 ms
73,672 KB
testcase_25 AC 118 ms
73,640 KB
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys,random,bisect
from collections import deque,defaultdict
from heapq import heapify,heappop,heappush
from itertools import permutations
from math import log,gcd

input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

INF = 10**18

N = int(input())
X = li()
A = li()
M = max(A)

assert M <= 200

if N==1:
    if A[0]==1:
        print(0)
    else:
        print(-1)
    exit()

dp = [[INF]*(M+3) for p in range(3)]
dp[0][A[0]] = (X[1]-X[0]) * (2 * A[0] - 2)
dp[1][A[0]] = (X[1]-X[0]) * (2 * A[0] - 1)
dp[2][A[0]] = (X[1]-X[0]) * (2 * A[0])

for i in range(1,N-1):
    ndp = [[INF]*(M+3) for p in range(3)]
    for j in range(1,M+3):
        #端におかない
        if j!=1:
            for k in range(-2*min(A[i],j-1),1):
                if A[i]+j+k < M+3:
                    ndp[0][A[i]+j+k] = min(ndp[0][A[i]+j+k],dp[0][j]+(X[i+1]-X[i])*(2*(A[i]+j+k)-2))
                    ndp[1][A[i]+j+k] = min(ndp[1][A[i]+j+k],dp[1][j]+(X[i+1]-X[i])*(2*(A[i]+j+k)-1))
                    ndp[2][A[i]+j+k] = min(ndp[2][A[i]+j+k],dp[2][j]+(X[i+1]-X[i])*(2*(A[i]+j+k)))
        
        #片端におく
        for k in range(-(2*min(A[i],j)-1),1):
            if A[i]+j+k < M+3:
                for p in range(2):
                    ndp[p][A[i]+j+k] = min(ndp[p][A[i]+j+k],dp[1][j]+(X[i+1]-X[i])*(2*(A[i]+j+k)-2+p))
                for p in range(1,3):
                    ndp[p][A[i]+j+k] = min(ndp[p][A[i]+j+k],dp[2][j]+(X[i+1]-X[i])*(2*(A[i]+j+k)-2+p))
        
        
        
        #p2,両端におく
        if 2 <= A[i]:
            for k in range(-(2*min(A[i],j+1)-2),-1):
                if A[i]+j+k < M+3:
                    for p in range(3):
                        ndp[p][A[i]+j+k] = min(ndp[p][A[i]+j+k],dp[2][j]+(X[i+1]-X[i])*(2*(A[i]+j+k)-2+p))
        
    dp = ndp

res = 10**17
for p in range(3):
    if p <= A[-1]:
        res = min(res,dp[p][A[-1]-p+1])

if res==10**17:
    print(-1)
else:
    print(res)
        
        





0