結果
| 問題 | No.3417 Tired Santa |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-12-24 03:19:18 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 56 ms / 2,000 ms |
| コード長 | 3,349 bytes |
| 記録 | |
| コンパイル時間 | 2,399 ms |
| コンパイル使用メモリ | 211,168 KB |
| 実行使用メモリ | 34,944 KB |
| 最終ジャッジ日時 | 2025-12-24 03:19:22 |
| 合計ジャッジ時間 | 4,361 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
//https://atcoder.jp/contests/joi2024ho/submissions/71732435
long long N,S,L = 1000000; cin >> N >> S;// >> L;
vector<long long> X(N);
for(auto &x : X) cin >> x;
sort(X.begin(),X.end());
vector<long long> Xs = X;
Xs.erase(unique(Xs.begin(),Xs.end()),Xs.end());
long long n = Xs.size();
long long Q = 1; //cin >> Q;
//if(n >= 1100){
// while(Q--) cout << "No\n";
// return 0;
//}
vector<long long> C(n);
for(auto &c : C) cin >> c;
//for(auto &x : X) C.at(lower_bound(Xs.begin(),Xs.end(),x)-Xs.begin())++;
auto Cl = C,Cr = C;
for(long long i=1; i<n; i++) Cl.at(i) += Cl.at(i-1);
for(long long i=n-2; i>=0; i--) Cr.at(i) += Cr.at(i+1);
vector<vector<long long>> L1(n,vector<long long>(n,8e18)),L2 = L1,R1 = L1,R2 = L1;
L1.at(0).at(n-1) = 0,R2.at(0).at(n-1) = 0;
for(long long len=n-1; len>0; len--){
for(long long l=0; l+len<n; l++){
long long r = l+len;
long long b = 0,d = Xs.at(r)-Xs.at(l);
if(l) b += Cl.at(l-1);
if(r < n-1) b += Cr.at(r+1);
L2.at(l).at(r) = min(L2.at(l).at(r),L1.at(l).at(r)+(b)*d);
L1.at(l).at(r) = min(L1.at(l).at(r),L2.at(l).at(r)+(b)*d);
R2.at(l).at(r) = min(R2.at(l).at(r),R1.at(l).at(r)+(b)*d);
R1.at(l).at(r) = min(R1.at(l).at(r),R2.at(l).at(r)+(b)*d);
b += C.at(l);
L1.at(l+1).at(r) = L1.at(l).at(r)+(b)*(Xs.at(l+1)-Xs.at(l));
R1.at(l+1).at(r) = R1.at(l).at(r)+(b)*(Xs.at(l+1)-Xs.at(l));
b -= C.at(l);
b += C.at(r);
L2.at(l).at(r-1) = L2.at(l).at(r)+(b)*(Xs.at(r)-Xs.at(r-1));
R2.at(l).at(r-1) = R2.at(l).at(r)+(b)*(Xs.at(r)-Xs.at(r-1));
}
}
while(Q--){
long long s = 0,g = S,t = 8e18; //cin >> s >> g >> t;
t -= N;
int pos = upper_bound(Xs.begin(),Xs.end(),g)-Xs.begin();
bool yes = false;
long long answer = 8e18;
{
long long time;
if(pos){
time = 0;//abs(Xs.at(0)-s);
time += min(L1.at(pos-1).at(pos-1),L2.at(pos-1).at(pos-1))+abs(Xs.at(pos-1)-g)*(Cl.back());
//if(time <= t) yes = true;
answer = min(answer,time);
}
if(pos < n){
time = 0;//abs(Xs.at(0)-s);
time += min(L1.at(pos).at(pos),L2.at(pos).at(pos))+abs(Xs.at(pos)-g)*(Cl.back());
//if(time <= t) yes = true;
answer = min(answer,time);
}
}
{
long long time;
if(pos){
time = 0;//abs(Xs.at(n-1)-s);
time += min(R1.at(pos-1).at(pos-1),R2.at(pos-1).at(pos-1))+abs(Xs.at(pos-1)-g)*(Cl.back());
//if(time <= t) yes = true;
answer = min(answer,time);
}
if(pos < n){
time = 0;//abs(Xs.at(n-1)-s);
time += min(R1.at(pos).at(pos),R2.at(pos).at(pos))+abs(Xs.at(pos)-g)*(Cl.back());
//if(time <= t) yes = true;
answer = min(answer,time);
}
}
//if(yes) cout << "Yes\n";
//else cout << "No\n";
cout << answer << "\n";
}
}