結果

問題 No.209 Longest Mountain Subsequence
ユーザー nebukuro09nebukuro09
提出日時 2017-05-30 21:40:42
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 1,322 bytes
コンパイル時間 772 ms
コンパイル使用メモリ 103,988 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-03 13:43:32
合計ジャッジ時間 2,274 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 81 ms
4,376 KB
testcase_02 AC 75 ms
4,380 KB
testcase_03 AC 278 ms
4,380 KB
testcase_04 AC 278 ms
4,376 KB
testcase_05 AC 68 ms
4,376 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;

immutable int INF = 10^^9 + 10;

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

    auto dp_left = new int[][](N, N + 1);
    foreach (i; 0..N)
        foreach (j; 0..N+1)
            dp_left[i][j] = j <= 1 ? 0 : INF;

    foreach (i; 0..N)
        foreach (j; 0..i)
            foreach (k; 1..N)
                if (dp_left[j][k-1] < H[i] - H[j])
                    dp_left[i][k] = min(dp_left[i][k], H[i] - H[j]);

    auto dp_right = new int[][](N, N + 1);
    foreach (i; 0..N)
        foreach (j; 0..N+1)
            dp_right[i][j] = j <= 1 ? 0 : INF;

    foreach (i; iota(N-1, -1, -1))
        foreach (j; iota(N-1, i, -1))
            foreach (k; 1..N)
                if (dp_right[j][k-1] < H[i] - H[j])
                    dp_right[i][k] = min(dp_right[i][k], H[i] - H[j]);


    int ans = 0;
    foreach (i; 0..N)
        foreach (j; 1..N+1)
            foreach (k; 1..N+1)
                if (dp_left[i][j] != INF && dp_right[i][k] != INF)
                    ans = max(ans, j + k - 1);
    ans.writeln;
}

void main() {
    auto T = readln.chomp.to!int;
    while (T--) solve;
}
0