結果
| 問題 |
No.209 Longest Mountain Subsequence
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-05-30 21:40:42 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,322 bytes |
| コンパイル時間 | 714 ms |
| コンパイル使用メモリ | 118,592 KB |
| 実行使用メモリ | 6,940 KB |
| 最終ジャッジ日時 | 2024-06-12 19:32:23 |
| 合計ジャッジ時間 | 2,046 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 5 WA * 1 |
ソースコード
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;
}