結果

問題 No.390 最長の数列
ユーザー ikdikd
提出日時 2017-11-16 16:32:42
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 718 ms / 5,000 ms
コード長 617 bytes
コンパイル時間 2,021 ms
コンパイル使用メモリ 91,620 KB
実行使用メモリ 9,744 KB
最終ジャッジ日時 2023-09-03 16:57:18
合計ジャッジ時間 3,875 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
4,376 KB
testcase_01 AC 17 ms
4,380 KB
testcase_02 AC 34 ms
4,380 KB
testcase_03 AC 29 ms
4,380 KB
testcase_04 AC 35 ms
4,380 KB
testcase_05 AC 45 ms
8,036 KB
testcase_06 AC 603 ms
8,152 KB
testcase_07 AC 15 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 16 ms
4,376 KB
testcase_10 AC 106 ms
8,160 KB
testcase_11 AC 121 ms
9,744 KB
testcase_12 AC 112 ms
8,096 KB
testcase_13 AC 157 ms
7,324 KB
testcase_14 AC 718 ms
8,384 KB
testcase_15 AC 1 ms
4,384 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 4 ms
4,380 KB
testcase_18 AC 6 ms
5,108 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

void main(){
  import std.stdio, std.string, std.conv, std.algorithm;
  import std.typecons;

  int n; rd(n);
  auto a=readln.split.to!(int[]);

  auto rec=new int[](n);
  fill(rec, 1);
  sort(a);
  size_t[int] pos;
  foreach(i, e; a) pos[e]=i;
  foreach(i, e0; a){
    for(auto e=e0*2; e<=1_000_000; e+=e0){
      if(e in pos){
        auto j=pos[e];
        rec[j]=max(rec[j], rec[i]+1);
      }
    }
  }

  writeln(reduce!(max)(rec));
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}
0