結果

問題 No.390 最長の数列
ユーザー te-shte-sh
提出日時 2017-07-26 16:16:10
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 109 ms / 5,000 ms
コード長 472 bytes
コンパイル時間 671 ms
コンパイル使用メモリ 95,108 KB
実行使用メモリ 15,500 KB
最終ジャッジ日時 2023-09-03 15:31:45
合計ジャッジ時間 2,398 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 38 ms
15,500 KB
testcase_06 AC 109 ms
15,080 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 6 ms
11,816 KB
testcase_09 AC 5 ms
9,940 KB
testcase_10 AC 44 ms
14,280 KB
testcase_11 AC 45 ms
15,160 KB
testcase_12 AC 43 ms
14,288 KB
testcase_13 AC 25 ms
13,572 KB
testcase_14 AC 36 ms
6,540 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 4 ms
10,964 KB
testcase_17 AC 6 ms
11,028 KB
testcase_18 AC 8 ms
10,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  auto n = readln.chomp.to!size_t;
  auto x = readln.split.to!(int[]);
  x.sort();

  auto maxX = x.back;

  auto b = new size_t[](maxX+1);
  b[] = n;
  foreach (i, xi; x) b[xi] = i;

  auto w = new int[](n);

  foreach (i, xi; x) {
    if (!w[i]) w[i] = 1;

    for (auto j = xi * 2; j <= maxX; j += xi)
      if (b[j] < n) w[b[j]] = max(w[b[j]], w[i] + 1);
  }

  writeln(w.maxElement);
}
0