結果

問題 No.127 門松もどき
ユーザー kimiyukikimiyuki
提出日時 2016-02-27 07:24:34
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 178 ms / 5,000 ms
コード長 995 bytes
コンパイル時間 782 ms
コンパイル使用メモリ 65,884 KB
実行使用メモリ 108,976 KB
最終ジャッジ日時 2023-08-25 14:09:54
合計ジャッジ時間 3,369 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 166 ms
108,948 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 10 ms
11,476 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 89 ms
58,732 KB
testcase_13 AC 126 ms
77,808 KB
testcase_14 AC 117 ms
71,352 KB
testcase_15 AC 155 ms
97,808 KB
testcase_16 AC 106 ms
68,976 KB
testcase_17 AC 128 ms
79,580 KB
testcase_18 AC 103 ms
66,332 KB
testcase_19 AC 61 ms
41,920 KB
testcase_20 AC 62 ms
42,892 KB
testcase_21 AC 28 ms
21,380 KB
testcase_22 AC 177 ms
108,976 KB
testcase_23 AC 178 ms
108,964 KB
testcase_24 AC 123 ms
84,128 KB
testcase_25 AC 150 ms
98,812 KB
testcase_26 AC 76 ms
50,420 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
template <typename T> bool setmax(T & l, T const & r) { if (not (l < r)) return false; l = r; return true; }
using namespace std;
int main() {
    int n; cin >> n;
    vector<int> a(n); repeat (i,n) cin >> a[i];
    vector<vector<vector<int> > > dp(2, vector<vector<int> >(n, vector<int>(n)));
    repeat (len,n+1) {
        repeat (l,n) {
            int r = l + len;
            if (n <= r) continue;
            if (l == r) {
                dp[0][l][r] = 1;
                dp[1][l][r] = 1;
            } else {
                dp[0][l][r] = dp[0][l][r-1];
                dp[1][l][r] = dp[1][l+1][r];
                if (a[l] < a[r]) setmax(dp[0][l][r], dp[1][l+1][r] + 1);
                if (a[l] > a[r]) setmax(dp[1][l][r], dp[0][l][r-1] + 1);
            }
        }
    }
    int ans = 0;
    repeat (j,n) setmax(ans, max(dp[0][j][n-1], dp[1][0][j]));
    cout << ans << endl;
    return 0;
}
0