結果
問題 |
No.390 最長の数列
|
ユーザー |
![]() |
提出日時 | 2018-01-28 02:36:27 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 63 ms / 5,000 ms |
コード長 | 707 bytes |
コンパイル時間 | 772 ms |
コンパイル使用メモリ | 110,536 KB |
実行使用メモリ | 12,660 KB |
最終ジャッジ日時 | 2024-06-12 23:40:37 |
合計ジャッジ時間 | 1,796 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 15 |
ソースコード
import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.typecons; int readint() { return readln.chomp.to!int; } int[] readints() { return readln.split.to!(int[]); } int calc(int[] xs) { auto dp = new int[xs.maxElement + 1]; auto set = new bool[dp.length]; foreach (x; xs) set[x] = true; foreach (x; xs.sort!((a, b) => a > b)) { for (int i = x; i < dp.length; i += x) { if (set[i]) { dp[x] = max(dp[x], dp[i] + 1); } } } return dp.maxElement; } void main() { readint; auto xs = readints; int ans = calc(xs); writeln(ans); }