結果

問題 No.3417 Tired Santa
コンテスト
ユーザー Kude
提出日時 2025-12-24 01:32:36
言語 C++23
(gcc 13.3.0 + boost 1.89.0)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 1,500 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,453 ms
コンパイル使用メモリ 300,356 KB
実行使用メモリ 19,596 KB
最終ジャッジ日時 2025-12-24 01:32:41
合計ジャッジ時間 5,164 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

ll dp[1010][1010][2];

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, s;
  cin >> n >> s;
  VI x(n);
  rep(i, n) cin >> x[i];
  VL w(n + 1);
  rep(i, n) cin >> w[i+1];
  rep(i, n) w[i+1] += w[i];
  constexpr long long INF = 1002003004005006007;
  rep(i, 1010) rep(j, 1010) rep(k, 2) dp[i][j][k] = INF;
  rep(i, n) dp[i][i][0] = abs(x[i] - s) * w[n];
  rrep(l, n) {
    for (int r = l; r < n; r++) rep(k, 2) if (ll val = dp[l][r][k]; val != INF) {
      int now = k == 0 ? x[l] : x[r];
      ll w_now = w[n] - (w[r+1] - w[l]);
      if (r + 1 < n) chmin(dp[l][r+1][1], val + (x[r+1] - now) * w_now);
      if (l) chmin(dp[l-1][r][0], val + (now - x[l-1]) * w_now);
    }
  }
  ll ans = min(dp[0][n-1][0], dp[0][n-1][1]);
  cout << ans << '\n';
}
0