結果
| 問題 |
No.31 悪のミックスジュース
|
| コンテスト | |
| ユーザー |
momoyuu
|
| 提出日時 | 2024-07-28 01:13:13 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 5,000 ms |
| コード長 | 1,001 bytes |
| コンパイル時間 | 1,280 ms |
| コンパイル使用メモリ | 95,824 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-28 01:13:16 |
| 合計ジャッジ時間 | 2,221 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 17 |
ソースコード
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
ll n,v;
cin>>n>>v;
vector<ll> c(n);
for(int i = 0;i<n;i++) cin>>c[i];
ll sum = 0;
for(int i = 0;i<n;i++) sum += c[i];
v -= n;
if(v<=0){
cout<<sum<<endl;
return 0;
}
vector<ll> a(n+1,0);
for(int i = 0;i<n;i++) a[i+1] += a[i] + c[i];
ll ans = 1e18;
vector<ll> dp(n*n+1,1e18);
dp[0] = 0;
for(int i = 0;i<=n*n;i++){
for(int j = 1;j<=n;j++){
if(i+j>n*n) continue;
dp[i+j] = min(dp[i+j],dp[i]+a[j]);
}
}
if(v<=n*n){
cout<<dp[v]<<endl;
return 0;
}
for(int i = 0;i<n;i++){
ll le = i + 1;
ll can = (v-n*n+le-1) / le;
ll nv = v - can * le;
ll now = sum + a[i+1] * can;
if(nv>=0) now += dp[nv];
ans = min(ans,now);
}
cout<<ans<<endl;
}
momoyuu