結果
| 問題 |
No.484 収穫
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-08-22 18:38:23 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 94 ms / 3,000 ms |
| コード長 | 4,017 bytes |
| コンパイル時間 | 1,926 ms |
| コンパイル使用メモリ | 198,460 KB |
| 最終ジャッジ日時 | 2025-01-24 01:33:04 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
ソースコード
bool TEST = false;
using namespace std;
#include<bits/stdc++.h>
#include<fstream>
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);i++)
#define repr(i,n) for(int (i)=(ll)(n)-1;(i)>=0;i--)
#define range(i,start,end,step) for(int (i)=start;(i)<(ll)(end);(i)+=(step))
#define dump(x) cerr << "Line " << __LINE__ << ": " << #x << " = " << (x) << "\n";
#define spa << " " <<
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define allr(a) (a).rbegin(),(a).rend()
using ld = long double;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T>>;
template<typename T, typename T2> using P = pair<T, T2>;
template<typename T, typename T2> using M = map<T, T2>;
template<typename T> using S = set<T>;
template<typename T, typename T2> using UM = unordered_map<T, T2>;
template<typename T> using PQ = priority_queue<T, V<T>, greater<T>>;
template<typename T> using rPQ = priority_queue<T, V<T>, less<T>>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<class SS, class T> ostream& operator << (ostream& os, const pair<SS, T> v){os << "(" << v.first << ", " << v.second << ")"; return os;}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<vector<T>> &v){ for(auto &e : v){os << e << "\n";} return os;}
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template <class T> void UNIQUE(vector<T> &x) {sort(ALL(x));x.erase(unique(ALL(x)), x.end());}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
void fail() { cout << -1 << '\n'; exit(0); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
template<typename T> void debug(vector<vector<T>>&v){for(ll i=0;i<v.size();i++)
{cerr<<v[i][0];for(ll j=1;j<v[i].size();j++)cerr spa v[i][j];cerr<<"\n";}};
template<typename T> void debug(vector<T>&v){if(v.size()!=0)cerr<<v[0];
for(ll i=1;i<v.size();i++)cerr spa v[i];
cerr<<"\n";};
template<typename T> P<T,T> divmod(T a, T b) {return make_pair(a/b, a%b);}
const ll INF = (1ll<<62);
// const ld EPS = 1e-10;
// const ld PI = acos(-1.0);
const ll mod = (int)1e9 + 7;
//const ll mod = 998244353;
ll dp[2][2010][2010];
int n;
V<ll> a;
ll cost(int l, int r, ll t) {
if (l<0 || l>=n || r<0 || r>=n) return INF;
return max(a[r], t + abs(l-r));
}
ll sub(bool b, int l, int r) {
if (l<0 || l>=n || r<0 || r>n) return INF;
if (dp[b][l][r]>=0) return dp[b][l][r];
ll res = INF;
if (!b) {
chmin(res, cost(l-2, l-1, sub(0,l-1,r)));
chmin(res, cost(r, l-1, sub(1,l-1,r)));
} else {
chmin(res, cost(l-1, r, sub(0,l,r+1)));
chmin(res, cost(r+1, r, sub(1,l,r+1)));
}
dp[b][l][r] = res;
// cout << b spa l spa r spa res << endl;
return res;
}
void Main(){
cin >> n;
a = V<ll>(n);
rep(i,n) cin >> a[i];
rep(b,2) rep(i,n+10) rep(j, n+10) dp[b][i][j] = -1;
dp[0][1][n] = a[0];
dp[1][0][n-1] = a[n-1];
ll ans = INF;
rep(i,n) {
chmin(ans, sub(0,i,i));
chmin(ans, sub(1,i,i));
}
cout << ans << endl;
}
int main(void){
std::ifstream in("tmp_in");
if (TEST) {
std::cin.rdbuf(in.rdbuf());
std::cout << std::fixed << std::setprecision(15);
} else {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
std::cout << std::fixed << std::setprecision(15);
}
Main();
}