結果

問題 No.390 最長の数列
ユーザー noriocnorioc
提出日時 2018-01-28 02:36:27
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 64 ms / 5,000 ms
コード長 707 bytes
コンパイル時間 781 ms
コンパイル使用メモリ 98,260 KB
実行使用メモリ 11,776 KB
最終ジャッジ日時 2023-09-03 18:25:44
合計ジャッジ時間 2,166 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 34 ms
10,584 KB
testcase_06 AC 64 ms
11,776 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 4 ms
7,400 KB
testcase_09 AC 5 ms
7,436 KB
testcase_10 AC 39 ms
11,520 KB
testcase_11 AC 39 ms
11,140 KB
testcase_12 AC 39 ms
10,812 KB
testcase_13 AC 21 ms
11,460 KB
testcase_14 AC 32 ms
6,212 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 4 ms
7,400 KB
testcase_17 AC 7 ms
7,748 KB
testcase_18 AC 7 ms
8,172 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];

    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);
}
0