結果

問題 No.390 最長の数列
ユーザー le_panda_noirle_panda_noir
提出日時 2020-06-13 18:33:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,149 ms / 5,000 ms
コード長 1,878 bytes
コンパイル時間 1,196 ms
コンパイル使用メモリ 120,020 KB
実行使用メモリ 21,264 KB
最終ジャッジ日時 2023-09-08 00:38:48
合計ジャッジ時間 6,795 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 740 ms
21,264 KB
testcase_06 AC 1,149 ms
8,032 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 575 ms
15,420 KB
testcase_11 AC 559 ms
15,444 KB
testcase_12 AC 573 ms
15,372 KB
testcase_13 AC 260 ms
7,072 KB
testcase_14 AC 386 ms
8,304 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 25 ms
4,564 KB
testcase_18 AC 40 ms
5,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;
using vi = vector<int>;

#define in(v) v; cin >> v;
void ins() {}
template<class T,class... Rest>void ins(T& v,Rest&... rest){cin>>v;ins(rest...);}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rrep(i,n) for(long long i=(n);i>=0;--i)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))

// ========== debug ==========
template<class T>ostream& operator<<(ostream& os,const vector<T>& vec){os<<"{";for(size_t i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
ostream& operator<<(ostream& os,const vector<char>&v){for(size_t i=0;i<v.size();++i)os<<v[i];return os;}
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>& rhs){os<<"("<<rhs.first<<", "<<rhs.second<<")";return os;}

#ifdef LOCAL
void debug() {cerr << "\n";}
template<class First> void debug(const First& first) {cerr<<first<<"\n";}
template<class First, class... Rest> void debug(const First& first, const Rest&... rest) {cerr<<first<<",";debug(rest...);}
void debug2() {cerr << "\n";}
template<class First> void debug2(const First& first) {cerr<<first<<" ";}
template<class First, class... Rest> void debug2(const First& first, const Rest&... rest) {cerr<<first<<" ";debug2(rest...);}
#else
#define debug(...) 42
#define debug2(...) 42
#endif
// ===========================

int main() {
  int N;
  ins(N);

  vi x(N);
  rep(i, N) {
    cin >> x[i];
  }
  all(sort, x);
  map<int, int> dp;
  int ans = 0;
  rep(i, N) {
    for (int j = 1; j * j <= x[i]; ++j) {
      if (x[i] % j == 0)
        dp[x[i]] = max(dp[x[i]], max(dp[j]+1, dp[x[i]/j]+1));
    }
    ans = max(ans, dp[x[i]]);
  }
  cout << ans << endl;

  return 0;
}
0