結果
| 問題 |
No.484 収穫
|
| コンテスト | |
| ユーザー |
momoyuu
|
| 提出日時 | 2024-09-30 00:10:18 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 667 ms / 3,000 ms |
| コード長 | 1,583 bytes |
| コンパイル時間 | 1,128 ms |
| コンパイル使用メモリ | 101,344 KB |
| 実行使用メモリ | 222,336 KB |
| 最終ジャッジ日時 | 2024-09-30 00:10:28 |
| 合計ジャッジ時間 | 9,942 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
ソースコード
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n;
cin>>n;
vector<ll> a(n);
for(int i = 0;i<n;i++) cin>>a[i];
ll ans = 1e18;
vector<vector<vector<ll>>> dp(n,vector<vector<ll>>(n,vector<ll>(2,1e18)));
dp[0][n-1][0] = -1;
dp[0][n-1][1] = -1;
for(int i = n;i>0;i--){
for(int j = 0;j<n;j++){
int le = j;
int ri = le + i - 1;
if(ri>=n) continue;
for(int t = 0;t<2;t++){
int p;
if(t==0) p = le - 1;
else p = ri + 1;
for(int nt = 0;nt<2;nt++){
int np;
if(nt==0) np = le;
else np = ri;
ll ti = dp[le][ri][t];
ti += abs(p-np);
if(nt==0) ti = max(ti,a[le]);
else ti = max(ti,a[ri]);
if(nt==0){
if(ri==le){
ans = min(ans,ti);
}else{
dp[le+1][ri][nt] = min(dp[le+1][ri][nt],ti);
}
}else{
if(ri==le){
ans = min(ans,ti);
}else{
dp[le][ri-1][nt] = min(dp[le][ri-1][nt],ti);
}
}
}
}
}
}
cout<<ans<<endl;
}
momoyuu