結果

問題 No.127 門松もどき
ユーザー kimiyukikimiyuki
提出日時 2016-02-27 07:11:05
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 945 bytes
コンパイル時間 586 ms
コンパイル使用メモリ 66,100 KB
実行使用メモリ 109,084 KB
最終ジャッジ日時 2023-10-24 18:22:24
合計ジャッジ時間 3,281 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,348 KB
testcase_06 WA -
testcase_07 AC 2 ms
4,348 KB
testcase_08 WA -
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 94 ms
58,888 KB
testcase_13 AC 127 ms
77,896 KB
testcase_14 AC 115 ms
71,560 KB
testcase_15 AC 162 ms
97,960 KB
testcase_16 AC 113 ms
69,184 KB
testcase_17 AC 127 ms
80,008 KB
testcase_18 AC 106 ms
66,544 KB
testcase_19 AC 61 ms
41,992 KB
testcase_20 AC 60 ms
43,048 KB
testcase_21 AC 28 ms
21,400 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

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);
            }
        }
    }
    cout << max(dp[0][0][n-1], dp[1][0][n-1]) << endl;
    return 0;
}
0