結果
問題 | No.209 Longest Mountain Subsequence |
ユーザー |
|
提出日時 | 2017-05-30 21:45:09 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 291 ms / 2,000 ms |
コード長 | 1,326 bytes |
コンパイル時間 | 995 ms |
コンパイル使用メモリ | 116,748 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-12 19:32:26 |
合計ジャッジ時間 | 2,182 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 6 |
ソースコード
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; }