結果

問題 No.390 最長の数列
ユーザー ttakanottakano
提出日時 2017-12-02 01:52:30
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 369 ms / 5,000 ms
コード長 921 bytes
コンパイル時間 2,552 ms
コンパイル使用メモリ 151,300 KB
実行使用メモリ 11,300 KB
最終ジャッジ日時 2023-08-18 18:54:49
合計ジャッジ時間 4,368 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
5,404 KB
testcase_01 AC 5 ms
5,504 KB
testcase_02 AC 5 ms
5,716 KB
testcase_03 AC 5 ms
5,400 KB
testcase_04 AC 5 ms
5,452 KB
testcase_05 AC 369 ms
4,376 KB
testcase_06 AC 283 ms
8,972 KB
testcase_07 AC 5 ms
5,452 KB
testcase_08 AC 5 ms
4,380 KB
testcase_09 AC 5 ms
5,392 KB
testcase_10 AC 275 ms
11,300 KB
testcase_11 AC 278 ms
8,076 KB
testcase_12 AC 272 ms
8,180 KB
testcase_13 AC 189 ms
8,144 KB
testcase_14 AC 129 ms
7,928 KB
testcase_15 AC 5 ms
5,392 KB
testcase_16 AC 6 ms
7,644 KB
testcase_17 AC 18 ms
8,204 KB
testcase_18 AC 26 ms
7,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
#define printall(n,array) for(int i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;
typedef long long ll;
typedef pair<int, int> PI;
typedef pair<int, PI> V;
typedef vector<int> VE;
const ll mod = 1000000007; //10^9+7

vector<int> enumdiv(int n){
  vector<int> s;
  for(int i=1;i*i<=n;i++){
    if(n%i==0){
      s.push_back(i);
      if(i*i!=n)s.push_back(n/i);
    }
  }
  sort(s.begin(),s.end());
  return s;
}


int main(){
  int n; cin>>n;
  int x[1000005];
  REP(i,n)cin>>x[i];
  int dp[1000005];
  REP(i,n)dp[x[i]]=1;
  sort(x,x+n);

  REP(i,1000002){
    if(dp[i]){
      auto v=enumdiv(i);
      for(int j:v){
        if(j!=i)dp[i]=max(dp[i],dp[j]+1);
      }
    }
  }
  
  int max_=0;
  //printall(440,dp);
  REP(i,n)max_=max(max_,dp[x[i]]);
  print(max_);
}
0