結果

問題 No.390 最長の数列
ユーザー DaYuanChiDaYuanChi
提出日時 2021-02-06 15:32:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 67 ms / 5,000 ms
コード長 477 bytes
コンパイル時間 1,628 ms
コンパイル使用メモリ 169,912 KB
実行使用メモリ 7,516 KB
最終ジャッジ日時 2023-09-15 23:26:33
合計ジャッジ時間 2,871 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
7,300 KB
testcase_01 AC 8 ms
7,248 KB
testcase_02 AC 9 ms
7,296 KB
testcase_03 AC 8 ms
7,260 KB
testcase_04 AC 9 ms
7,260 KB
testcase_05 AC 38 ms
4,380 KB
testcase_06 AC 55 ms
7,436 KB
testcase_07 AC 7 ms
7,260 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 8 ms
7,252 KB
testcase_10 AC 45 ms
7,516 KB
testcase_11 AC 46 ms
7,500 KB
testcase_12 AC 46 ms
7,376 KB
testcase_13 AC 36 ms
7,456 KB
testcase_14 AC 67 ms
7,448 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 3 ms
4,492 KB
testcase_17 AC 8 ms
7,264 KB
testcase_18 AC 9 ms
7,284 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int dp[1000005];

int main(){
  int n; cin >> n;
  vector<int> x(n);
  for(int i = 0; i < n; i++) cin >> x[i];
  sort(x.begin(), x.end());
  for(int i = 0; i < n; i++){
    for(int j = x[i]; j <= 1000005; j += x[i]){
      if(j==x[i]) dp[j]++;
      dp[j] = max(dp[j], dp[x[i]]);
    }
  }
  int ans = 0;
  for(int i = 0; i < n; i++) ans = max(ans, dp[x[i]]);
  cout << ans << endl;
  return 0;
}
  
        
0