結果
問題 | No.127 門松もどき |
ユーザー |
|
提出日時 | 2018-02-08 16:03:59 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 179 ms / 5,000 ms |
コード長 | 889 bytes |
コンパイル時間 | 668 ms |
コンパイル使用メモリ | 117,396 KB |
実行使用メモリ | 75,760 KB |
最終ジャッジ日時 | 2024-06-12 23:48:38 |
合計ジャッジ時間 | 3,663 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 23 |
ソースコード
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;}