結果

問題 No.390 最長の数列
コンテスト
ユーザー yuppe19 😺
提出日時 2017-06-18 14:29:24
言語 C++11(old_compat)
(gcc 12.4.0 + boost 1.89.0)
コンパイル:
g++-12 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -include bits/stdc++.h -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 53 ms / 5,000 ms
コード長 541 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,456 ms
コンパイル使用メモリ 170,968 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2026-03-08 01:31:21
合計ジャッジ時間 3,064 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 15
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:8:15: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    8 |   int n; scanf("%d", &n);
      |          ~~~~~^~~~~~~~~~
main.cpp:11:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   11 |     scanf("%d", &x[i]);
      |     ~~~~~^~~~~~~~~~~~~

ソースコード

diff #
raw source code

#include <iostream>
#include <algorithm>
using namespace std;

int main(void) {
  constexpr int N = int(pow(10, 6)) + 10;
  vector<int> dp(N, 0); // dp[N]
  int n; scanf("%d", &n);
  vector<int> x(n, 0); // x[n]
  for(int i=0; i<n; ++i) {
    scanf("%d", &x[i]);
    dp[x[i]] = 1;
  }
  sort(begin(x), end(x));
  for(int i=0; i<n; ++i) {
    for(int a=x[i]*2; a<=N; a+=x[i]) {
      if(!dp[a]) { continue; }
      dp[a] = max(dp[a], dp[x[i]] + 1);
    }
  }
  int res = *max_element(begin(dp), end(dp));
  printf("%d\n", res);
  return 0;
}
0