結果

問題 No.390 最長の数列
ユーザー peroonperoon
提出日時 2019-04-14 14:11:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,196 ms / 5,000 ms
コード長 1,536 bytes
コンパイル時間 1,246 ms
コンパイル使用メモリ 108,712 KB
実行使用メモリ 11,740 KB
最終ジャッジ日時 2023-10-19 03:22:09
合計ジャッジ時間 7,697 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1,196 ms
11,740 KB
testcase_06 AC 963 ms
11,740 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 7 ms
10,948 KB
testcase_09 AC 6 ms
10,948 KB
testcase_10 AC 858 ms
11,740 KB
testcase_11 AC 853 ms
11,740 KB
testcase_12 AC 856 ms
11,740 KB
testcase_13 AC 571 ms
11,740 KB
testcase_14 AC 330 ms
4,816 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 6 ms
10,948 KB
testcase_17 AC 45 ms
11,212 KB
testcase_18 AC 69 ms
11,212 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<fstream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

set<ll> factorization(ll N){
    set<ll> se;
    for(int i=1; i*i<=N; i++){
        if(N%i==0){
            se.insert(i);
            se.insert(N/i);
        }
    }
    return se;
}

vector<ll> dp;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    // input
    ll N;
    cin >> N;

    vector<ll> A(N);
    FOR(i, 0, N){
        cin >> A.at(i);
    }
    sort(ALL(A));
    ll max_v = A.back();

    dp.resize(max_v + 1);

    for(ll a : A){
        dp[a] = 1;
    }

    for(ll a : A){
        auto se = factorization(a);
        for(ll v : se){
            if(v<a){
                dp[a] = max(dp[a], dp[v]+1);
            }
        }
    }

    ll answer = dp[1];
    FOR(i, 0, max_v+1){
        answer = max(answer, dp[i]);
    }

    p(answer);
    
    return 0;
}
0