結果

問題 No.705 ゴミ拾い Hard
ユーザー vwxyzvwxyz
提出日時 2023-05-28 04:20:41
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 2,107 bytes
コンパイル時間 185 ms
コンパイル使用メモリ 11,092 KB
実行使用メモリ 70,176 KB
最終ジャッジ日時 2023-08-27 03:32:43
合計ジャッジ時間 4,886 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
12,828 KB
testcase_01 AC 16 ms
8,512 KB
testcase_02 AC 16 ms
8,508 KB
testcase_03 AC 16 ms
8,456 KB
testcase_04 AC 16 ms
8,544 KB
testcase_05 AC 16 ms
8,428 KB
testcase_06 AC 16 ms
8,352 KB
testcase_07 AC 16 ms
8,480 KB
testcase_08 AC 16 ms
8,500 KB
testcase_09 AC 16 ms
8,520 KB
testcase_10 AC 16 ms
8,476 KB
testcase_11 AC 16 ms
8,584 KB
testcase_12 AC 15 ms
8,384 KB
testcase_13 AC 16 ms
8,500 KB
testcase_14 AC 33 ms
8,588 KB
testcase_15 AC 32 ms
8,588 KB
testcase_16 AC 32 ms
8,596 KB
testcase_17 AC 32 ms
8,484 KB
testcase_18 AC 33 ms
8,472 KB
testcase_19 AC 32 ms
8,608 KB
testcase_20 AC 33 ms
8,508 KB
testcase_21 AC 33 ms
8,652 KB
testcase_22 AC 33 ms
8,652 KB
testcase_23 AC 33 ms
8,556 KB
testcase_24 TLE -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
権限があれば一括ダウンロードができます

ソースコード

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):
    return abs(X[l]-A[r-1])**3+abs(Y[l])**3
ans=monotone_minima(N,cost,inf=inf)
print(ans)
0