結果
問題 |
No.484 収穫
|
ユーザー |
|
提出日時 | 2017-02-24 22:04:25 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 92 ms / 3,000 ms |
コード長 | 1,345 bytes |
コンパイル時間 | 754 ms |
コンパイル使用メモリ | 75,408 KB |
実行使用メモリ | 50,304 KB |
最終ジャッジ日時 | 2024-10-13 13:15:16 |
合計ジャッジ時間 | 2,540 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
#include <iostream> #include <vector> #define repeat(i,n) for (int i = 0; (i) < int(n); ++(i)) #define repeat_reverse(i,n) for (int i = (n)-1; (i) >= 0; --(i)) using namespace std; template <class T> inline void setmin(T & a, T const & b) { a = min(a, b); } template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); } template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); } const int inf = 1.01e9; int main() { int n; cin >> n; vector<int> a(n); repeat (i,n) cin >> a[i]; auto dp = vectors(2, n+1, n+1, inf); dp[false][1][n] = a[0]; dp[true][0][n-1] = a[n-1]; repeat_reverse (len,n+1) { repeat (l,n-len+1) { int r = l + len; if (0 <= l-1) { setmin(dp[false][l][r], max(dp[false][l-1][r]+1, a[l-1])); setmin(dp[false][l][r], max(dp[true ][l-1][r]+r-l+1, a[l-1])); } if (r+1 < n+1) { setmin(dp[true][l][r], max(dp[false][l][r+1]+r-l+1, a[r])); setmin(dp[true][l][r], max(dp[true ][l][r+1]+1, a[r])); } } } int ans = inf; repeat (p,2) repeat (l,n+1) setmin(ans, dp[p][l][l]); cout << ans << endl; return 0; }