結果

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

ソースコード

diff #
raw source code

from bisect import bisect_left
import sys
sys.setrecursionlimit(10**6)

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))

if p+1 < N:
    d = X[p] - S
    ans = min(ans, w * d + f(p, w, p, p))

print(ans)
0