結果

問題 No.390 最長の数列
ユーザー noriocnorioc
提出日時 2018-01-28 02:30:18
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 535 ms / 5,000 ms
コード長 686 bytes
コンパイル時間 664 ms
コンパイル使用メモリ 98,160 KB
実行使用メモリ 15,652 KB
最終ジャッジ日時 2023-09-03 18:25:41
合計ジャッジ時間 2,976 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 60 ms
13,780 KB
testcase_06 AC 535 ms
13,820 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 5 ms
6,468 KB
testcase_09 AC 19 ms
7,188 KB
testcase_10 AC 116 ms
13,748 KB
testcase_11 AC 128 ms
14,080 KB
testcase_12 AC 122 ms
15,652 KB
testcase_13 AC 156 ms
14,168 KB
testcase_14 AC 108 ms
11,308 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 5 ms
7,144 KB
testcase_17 AC 8 ms
6,968 KB
testcase_18 AC 10 ms
8,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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];

    bool[int] m;
    foreach (x; xs) m[x] = true;

    foreach (x; xs.sort!((a, b) => a > b)) {
        for (int i = x; i < dp.length; i += x) {
            if (i in m) {
                dp[x] = max(dp[x], dp[i] + 1);
            }
        }
    }
    return dp.maxElement;
}

void main() {
    readint;
    auto xs = readints;
    int ans = calc(xs);
    writeln(ans);
}
0