結果
| 問題 | No.3417 Tired Santa |
| コンテスト | |
| ユーザー |
norioc
|
| 提出日時 | 2025-12-24 01:43:54 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 922 ms / 2,000 ms |
| コード長 | 1,053 bytes |
| 記録 | |
| コンパイル時間 | 520 ms |
| コンパイル使用メモリ | 82,812 KB |
| 実行使用メモリ | 254,360 KB |
| 最終ジャッジ日時 | 2025-12-24 01:44:03 |
| 合計ジャッジ時間 | 8,472 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 |
ソースコード
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 < N:
d = X[p] - S
ans = min(ans, w * d + f(p, w, p, p))
print(ans)
norioc