結果

問題 No.390 最長の数列
ユーザー alpha_virginisalpha_virginis
提出日時 2016-12-15 23:30:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 48 ms / 5,000 ms
コード長 954 bytes
コンパイル時間 1,636 ms
コンパイル使用メモリ 164,444 KB
実行使用メモリ 7,760 KB
最終ジャッジ日時 2024-04-10 10:13:29
合計ジャッジ時間 2,713 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
6,816 KB
testcase_01 AC 5 ms
6,940 KB
testcase_02 AC 5 ms
6,940 KB
testcase_03 AC 5 ms
6,944 KB
testcase_04 AC 6 ms
6,940 KB
testcase_05 AC 16 ms
6,940 KB
testcase_06 AC 48 ms
7,600 KB
testcase_07 AC 4 ms
6,940 KB
testcase_08 AC 4 ms
6,940 KB
testcase_09 AC 5 ms
6,940 KB
testcase_10 AC 27 ms
7,632 KB
testcase_11 AC 28 ms
7,504 KB
testcase_12 AC 28 ms
7,752 KB
testcase_13 AC 19 ms
7,692 KB
testcase_14 AC 33 ms
6,940 KB
testcase_15 AC 3 ms
6,944 KB
testcase_16 AC 4 ms
6,944 KB
testcase_17 AC 6 ms
7,628 KB
testcase_18 AC 7 ms
7,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dumpi(x1) fprintf(stderr, "#%s.%d (%s) = (%d)\n", __func__, __LINE__, #x1, x1);
#define dumpii(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%d, %d)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);

int n;
int xs[1123456];

int main() {
  scanf("%d", &n);
  for(int i = 0; i < n; ++i) {
    int a;
    scanf("%d", &a);
    xs[a] = 1;
  }

  for(int i = 1; i < 1123456; ++i) {
    if( xs[i] == 0 ) continue;
    for(int j = i + i; j < 1123456; j+=i) {
      if( xs[j] != 0 ) xs[j] = std::max(xs[j], xs[i] + 1);
    }
  }
  int res = -1;
  for(int i = 0; i < 1123456; ++i) {
    // if( i < 100 ) dumpi(xs[i]);
    res = std::max(res, xs[i]);
  }
  printf("%d\n", res);

  return 0;
}
0