結果

問題 No.390 最長の数列
ユーザー hanbei_dayohanbei_dayo
提出日時 2020-08-18 12:33:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 387 ms / 5,000 ms
コード長 1,155 bytes
コンパイル時間 1,072 ms
コンパイル使用メモリ 106,956 KB
実行使用メモリ 7,680 KB
最終ジャッジ日時 2024-04-20 07:30:12
合計ジャッジ時間 3,658 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 387 ms
5,376 KB
testcase_06 AC 259 ms
7,680 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 274 ms
7,564 KB
testcase_11 AC 275 ms
7,560 KB
testcase_12 AC 275 ms
7,568 KB
testcase_13 AC 198 ms
7,436 KB
testcase_14 AC 116 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 18 ms
7,424 KB
testcase_18 AC 27 ms
7,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include<random>
#include <bitset>
#include <cassert>
#include <complex>
using namespace std;
#define N (1000000000+7)
//#define N 998244353
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1e8;


ll gcd(ll a, ll b) {
	if (b > a) {
		ll tmp = b;
		b = a;
		a = tmp;
	}
	if (a%b == 0)return b;
	else return gcd(b, a%b);
}

int dp[1000010];

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++){
        dp[x[i]]=max(dp[x[i]],1);
        int m = x[i];
        for(int j=1;j*j<=m;j++){
            if(m%j==0){
                int t1 = j;
                int t2 = m/j;
                if(x[i]>t1)dp[x[i]]=max(dp[x[i]],dp[t1]+1);
                if(x[i]>t2)dp[x[i]]=max(dp[x[i]],dp[t2]+1);
            }
        }
    }
    int ans = 0;
    for(int i=1;i<=1000000;i++){
        ans = max(ans,dp[i]);
    }
    cout<<ans<<endl;
}
0