結果

問題 No.704 ゴミ拾い Medium
ユーザー vwxyzvwxyz
提出日時 2023-05-28 04:24:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,381 ms / 1,500 ms
コード長 2,147 bytes
コンパイル時間 390 ms
コンパイル使用メモリ 87,200 KB
実行使用メモリ 165,204 KB
最終ジャッジ日時 2023-08-27 03:34:59
合計ジャッジ時間 33,762 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,188 KB
testcase_01 AC 71 ms
71,164 KB
testcase_02 AC 70 ms
71,212 KB
testcase_03 AC 69 ms
71,400 KB
testcase_04 AC 72 ms
71,272 KB
testcase_05 AC 72 ms
71,516 KB
testcase_06 AC 72 ms
71,152 KB
testcase_07 AC 72 ms
71,456 KB
testcase_08 AC 72 ms
71,092 KB
testcase_09 AC 73 ms
71,308 KB
testcase_10 AC 72 ms
71,240 KB
testcase_11 AC 73 ms
71,348 KB
testcase_12 AC 72 ms
71,276 KB
testcase_13 AC 72 ms
71,080 KB
testcase_14 AC 136 ms
78,248 KB
testcase_15 AC 131 ms
77,532 KB
testcase_16 AC 128 ms
77,820 KB
testcase_17 AC 139 ms
78,408 KB
testcase_18 AC 121 ms
77,648 KB
testcase_19 AC 125 ms
77,772 KB
testcase_20 AC 128 ms
78,036 KB
testcase_21 AC 131 ms
77,688 KB
testcase_22 AC 123 ms
77,592 KB
testcase_23 AC 126 ms
77,772 KB
testcase_24 AC 1,229 ms
162,408 KB
testcase_25 AC 1,381 ms
162,796 KB
testcase_26 AC 1,175 ms
162,824 KB
testcase_27 AC 1,130 ms
162,620 KB
testcase_28 AC 1,205 ms
162,908 KB
testcase_29 AC 1,159 ms
162,552 KB
testcase_30 AC 1,184 ms
162,500 KB
testcase_31 AC 1,218 ms
162,772 KB
testcase_32 AC 1,166 ms
162,600 KB
testcase_33 AC 1,146 ms
162,608 KB
testcase_34 AC 1,213 ms
160,668 KB
testcase_35 AC 1,119 ms
160,036 KB
testcase_36 AC 1,138 ms
160,288 KB
testcase_37 AC 1,111 ms
159,996 KB
testcase_38 AC 1,129 ms
160,288 KB
testcase_39 AC 1,119 ms
160,212 KB
testcase_40 AC 1,178 ms
159,896 KB
testcase_41 AC 1,121 ms
160,156 KB
testcase_42 AC 1,140 ms
160,776 KB
testcase_43 AC 1,151 ms
160,076 KB
testcase_44 AC 70 ms
71,348 KB
testcase_45 AC 71 ms
71,228 KB
testcase_46 AC 1,076 ms
165,204 KB
testcase_47 AC 1,133 ms
164,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline=sys.stdin.readline

def monotone_minima(N,cost,cnt=0,inf=1<<60):
    dp=[inf]*(N+1)
    dp[0]=0
    if cnt:
        for _ in range(cnt):
            prev=dp
            dp=[inf]*(N+1)
            idx=[None]*(N+1)
            dp[0]=0
            idx[0]=0
            for n in range(N+1):
                if prev[n]+cost(n,N)<dp[N]:
                    dp[N]=prev[n]+cost(n,N)
                    idx[N]=n
            while inf in dp:
                lst=[i for i in range(N+1) if dp[i]!=inf]
                for l,r in zip(lst,lst[1:]):
                    mid=(l+r)//2
                    for n in range(idx[l],min(idx[r],mid)+1):
                        if prev[n]+cost(n,mid)<dp[mid]:
                            dp[mid]=prev[n]+cost(n,mid)
                            idx[mid]=n
    else:
        def transition(L,R):
            if R-L<=1:
                return
            mid=(L+R)//2
            transition(L,mid)
            update=[inf]*(R-mid)
            idx=[inf]*(R-mid)
            for n in range(L,mid):
                if dp[n]+cost(n,mid)<update[0]:
                    update[0]=dp[n]+cost(n,mid)
                    idx[0]=n
                if dp[n]+cost(n,R-1)<update[R-mid-1]:
                    update[R-mid-1]=dp[n]+cost(n,R-1)
                    idx[R-mid-1]=n
            while inf in update:
                lst=[i+mid for i in range(R-mid) if update[i]!=inf]
                for l,r in zip(lst,lst[1:]):
                    m=(l+r)//2
                    for n in range(idx[l-mid],min(idx[r-mid],m)+1):
                        if dp[n]+cost(n,m)<update[m-mid]:
                            update[m-mid]=dp[n]+cost(n,m)
                            idx[m-mid]=n
            for n in range(mid,R):
                dp[n]=min(dp[n],update[n-mid])
            transition(mid,R)
        transition(0,N+1)
    return dp[N]

N=int(readline())
A=list(map(int,readline().split()))
X=list(map(int,readline().split()))
Y=list(map(int,readline().split()))
inf=1<<60
def cost(l,r):
    assert l<=r
    if l==r:
        return 0
    return abs(X[l]-A[r-1])+abs(Y[l])
ans=monotone_minima(N,cost,inf=inf)
print(ans)
0