結果
| 問題 | No.3417 Tired Santa |
| コンテスト | |
| ユーザー |
Nachia
|
| 提出日時 | 2025-12-24 11:33:30 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 15 ms / 2,000 ms |
| コード長 | 1,235 bytes |
| 記録 | |
| コンパイル時間 | 757 ms |
| コンパイル使用メモリ | 81,768 KB |
| 実行使用メモリ | 11,008 KB |
| 最終ジャッジ日時 | 2025-12-24 11:33:32 |
| 合計ジャッジ時間 | 2,323 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 |
ソースコード
#ifdef NACHIA
#define _GLIBCXX_DEBUG
#else
#define NDEBUG
#endif
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
const ll INF = 1ll << 60;
#define REP(i,n) for(ll i=0; i<ll(n); i++)
template <class T> using V = vector<T>;
template <class A, class B> void chmax(A& l, const B& r){ if(l < r) l = r; }
template <class A, class B> void chmin(A& l, const B& r){ if(r < l) l = r; }
void testcase(){
ll N, S; cin >> N >> S;
V<ll> X(N); REP(I,N) cin >> X[I];
V<ll> W(N); REP(i,N) cin >> W[i];
V<V<ll>> dp(N, V<ll>(N,INF));
V<ll> sum(N+1); REP(i,N) sum[i+1] = sum[i] + W[i];
REP(i,N) dp[i][i] = abs(S - X[i]) * sum[N];
for(ll d=0; d<=N-1; d++){
for(ll l=0; l+d<N; l++){
ll r = l + d;
ll w = sum[N] - sum[r+1] + sum[l];
if(0 < l) chmin(dp[l-1][r], dp[l][r] + w * (X[l] - X[l-1]));
if(0 < l) chmin(dp[l-1][r], dp[r][l] + w * (X[r] - X[l-1]));
if(r+1 < N) chmin(dp[r+1][l], dp[l][r] + w * (X[r+1] - X[l]));
if(r+1 < N) chmin(dp[r+1][l], dp[r][l] + w * (X[r+1] - X[r]));
}
}
ll ans = min(dp[0][N-1], dp[N-1][0]);
cout << ans << "\n";
}
int main(){
cin.tie(0)->sync_with_stdio(0);
testcase();
return 0;
}
Nachia