結果

問題 No.484 収穫
ユーザー kimiyukikimiyuki
提出日時 2017-02-24 22:04:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 84 ms / 3,000 ms
コード長 1,345 bytes
コンパイル時間 819 ms
コンパイル使用メモリ 75,848 KB
実行使用メモリ 50,432 KB
最終ジャッジ日時 2024-04-21 14:29:54
合計ジャッジ時間 2,522 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 83 ms
50,432 KB
testcase_13 AC 81 ms
50,304 KB
testcase_14 AC 80 ms
50,432 KB
testcase_15 AC 82 ms
50,304 KB
testcase_16 AC 81 ms
50,432 KB
testcase_17 AC 81 ms
50,304 KB
testcase_18 AC 81 ms
50,304 KB
testcase_19 AC 82 ms
50,432 KB
testcase_20 AC 80 ms
50,432 KB
testcase_21 AC 81 ms
50,304 KB
testcase_22 AC 82 ms
50,304 KB
testcase_23 AC 84 ms
50,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0