結果
問題 | No.209 Longest Mountain Subsequence |
ユーザー | nebukuro09 |
提出日時 | 2017-05-30 21:45:09 |
言語 | D (dmd 2.107.1) |
結果 |
AC
|
実行時間 | 301 ms / 2,000 ms |
コード長 | 1,326 bytes |
コンパイル時間 | 673 ms |
コンパイル使用メモリ | 104,096 KB |
実行使用メモリ | 4,380 KB |
最終ジャッジ日時 | 2023-09-03 13:43:35 |
合計ジャッジ時間 | 2,264 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 102 ms
4,380 KB |
testcase_01 | AC | 87 ms
4,376 KB |
testcase_02 | AC | 81 ms
4,376 KB |
testcase_03 | AC | 301 ms
4,380 KB |
testcase_04 | AC | 301 ms
4,380 KB |
testcase_05 | AC | 73 ms
4,380 KB |
ソースコード
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+1) 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+1) 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; }