結果

問題 No.127 門松もどき
ユーザー nebukuro09nebukuro09
提出日時 2018-02-08 16:03:59
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 195 ms / 5,000 ms
コード長 889 bytes
コンパイル時間 726 ms
コンパイル使用メモリ 105,376 KB
実行使用メモリ 76,648 KB
最終ジャッジ日時 2023-09-03 18:38:10
合計ジャッジ時間 4,411 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 191 ms
75,896 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 16 ms
9,648 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 109 ms
55,604 KB
testcase_13 AC 142 ms
63,568 KB
testcase_14 AC 131 ms
61,860 KB
testcase_15 AC 179 ms
72,752 KB
testcase_16 AC 128 ms
60,532 KB
testcase_17 AC 141 ms
65,256 KB
testcase_18 AC 119 ms
58,448 KB
testcase_19 AC 71 ms
32,008 KB
testcase_20 AC 72 ms
32,864 KB
testcase_21 AC 38 ms
23,712 KB
testcase_22 AC 195 ms
75,408 KB
testcase_23 AC 192 ms
76,648 KB
testcase_24 AC 150 ms
66,380 KB
testcase_25 AC 175 ms
72,516 KB
testcase_26 AC 86 ms
34,852 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

immutable long MOD = 10^^9 + 7;

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!int).array;

    auto dp1 = new int[][](N, N);
    auto dp2 = new int[][](N, N);
    foreach (i; 0..N) dp1[i][i] = dp2[i][i] = 1;

    foreach (len; 2..N+1) {
        foreach (l; 0..N-len+1) {
            int r = l + len - 1;
            dp1[l][r] = dp1[l][r-1];
            if (A[l] < A[r]) dp1[l][r] = max(dp1[l][r], dp2[l+1][r] + 1);
            dp2[l][r] = dp2[l+1][r];
            if (A[l] > A[r]) dp2[l][r] = max(dp2[l][r], dp1[l][r-1] + 1);
        } 
    }

    int ans = 0;
    foreach (i; 0..N) foreach (j; 0..N) ans = max(ans, dp1[i][j], dp2[i][j]);
    ans.writeln;
}
0