結果

問題 No.390 最長の数列
ユーザー oxyshoweroxyshower
提出日時 2020-01-13 19:18:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 77 ms / 5,000 ms
コード長 527 bytes
コンパイル時間 1,572 ms
コンパイル使用メモリ 169,668 KB
実行使用メモリ 11,704 KB
最終ジャッジ日時 2023-08-23 11:28:00
合計ジャッジ時間 3,083 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
10,880 KB
testcase_01 AC 7 ms
10,776 KB
testcase_02 AC 7 ms
10,788 KB
testcase_03 AC 7 ms
10,696 KB
testcase_04 AC 8 ms
10,808 KB
testcase_05 AC 41 ms
11,588 KB
testcase_06 AC 64 ms
11,556 KB
testcase_07 AC 7 ms
10,764 KB
testcase_08 AC 5 ms
10,904 KB
testcase_09 AC 6 ms
10,740 KB
testcase_10 AC 46 ms
11,568 KB
testcase_11 AC 47 ms
11,564 KB
testcase_12 AC 46 ms
11,704 KB
testcase_13 AC 37 ms
11,644 KB
testcase_14 AC 77 ms
11,564 KB
testcase_15 AC 4 ms
10,856 KB
testcase_16 AC 5 ms
10,852 KB
testcase_17 AC 7 ms
10,812 KB
testcase_18 AC 7 ms
11,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

signed main(){

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

  vector<int> v(1000001, 1);
  for(int i = 0; i < n; i++){
    for(int j = a[i]*2; j < 1000001; j+=a[i]){
      v[j] = max(v[j], v[a[i]] + 1);
    }
  }

  int ans = 0;
  for(int i = 0; i < n; i++){
    ans = max(ans, v[a[i]]);
  }
  cout << ans << endl;

  return 0;
}
0