結果

問題 No.390 最長の数列
ユーザー oxyshoweroxyshower
提出日時 2019-03-03 00:37:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 59 ms / 5,000 ms
コード長 512 bytes
コンパイル時間 1,491 ms
コンパイル使用メモリ 170,672 KB
実行使用メモリ 11,708 KB
最終ジャッジ日時 2023-09-05 17:36:37
合計ジャッジ時間 2,682 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
10,748 KB
testcase_01 AC 6 ms
10,760 KB
testcase_02 AC 7 ms
10,820 KB
testcase_03 AC 6 ms
10,696 KB
testcase_04 AC 7 ms
10,800 KB
testcase_05 AC 22 ms
11,540 KB
testcase_06 AC 42 ms
11,536 KB
testcase_07 AC 5 ms
10,760 KB
testcase_08 AC 5 ms
10,852 KB
testcase_09 AC 5 ms
10,692 KB
testcase_10 AC 27 ms
11,708 KB
testcase_11 AC 27 ms
11,548 KB
testcase_12 AC 26 ms
11,500 KB
testcase_13 AC 21 ms
11,616 KB
testcase_14 AC 59 ms
11,484 KB
testcase_15 AC 4 ms
10,784 KB
testcase_16 AC 5 ms
10,736 KB
testcase_17 AC 5 ms
11,044 KB
testcase_18 AC 6 ms
10,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n; cin >> n;
  vector<int> x(n);
  for(int i = 0; i < n; i++){
    cin >> x[i];
  }
  sort(x.begin(),x.end());

  vector<int> dp(1000000+1,0);
  for(int i : x){
    dp[i] = max(dp[i],1LL);
    for(int j = i*2; j <= 1000000; j+=i){
      dp[j] = max(dp[j],dp[i]+1);
    }
  }

  int ans = 0;
  for(int i : x){
    ans = max(ans,dp[i]);
  }
  cout << ans << endl;

  return 0;
}
0