結果

問題 No.390 最長の数列
ユーザー ikd
提出日時 2017-11-14 18:44:38
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 721 ms / 5,000 ms
コード長 617 bytes
コンパイル時間 1,076 ms
コンパイル使用メモリ 105,880 KB
実行使用メモリ 7,692 KB
最終ジャッジ日時 2024-06-12 22:32:15
合計ジャッジ時間 3,677 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

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, e; a){
    for(auto t=2; e*t<=1_000_000; t++){
      if(e*t in pos){
        auto j=pos[e*t];
        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