結果

問題 No.3417 Tired Santa
コンテスト
ユーザー norioc
提出日時 2025-12-24 01:35:01
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 994 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 326 ms
コンパイル使用メモリ 82,380 KB
実行使用メモリ 254,452 KB
最終ジャッジ日時 2025-12-24 01:35:10
合計ジャッジ時間 8,541 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23 RE * 2
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from bisect import bisect_left

INF = 1 << 62
N, S = map(int, input().split())
X = list(map(int, input().split()))
W = list(map(int, input().split()))


memo = {}
def f(p, w, l, r):
    if l == 0 and r == N-1:
        return 0

    if (p, w, l, r) in memo: return memo[p, w, l, r]
    res = INF
    w2 = w - W[p]
    if p == l:
        if l > 0:
            d = X[p] - X[p-1]
            res = min(res, w2 * d + f(l-1, w2, l-1, r))

        if r+1 < N:
            d = X[r+1] - X[p]
            res = min(res, w2 * d + f(r+1, w2, l, r+1))

    if p == r:
        if l > 0:
            d = X[p] - X[l-1]
            res = min(res, w2 * d + f(l-1, w2, l-1, r))

        if r+1 < N:
            d = X[r+1] - X[p]
            res = min(res, w2 * d + f(r+1, w2, l, r+1))

    memo[p, w, l, r] = res
    return res


ans = INF
w = sum(W)
p = bisect_left(X, S)
if p > 0:
    d = S - X[p-1]
    ans = min(ans, w * d + f(p-1, w, p-1, p-1))

d = X[p] - S
ans = min(ans, w * d + f(p, w, p, p))
print(ans)
0