結果

問題 No.979 Longest Divisor Sequence
ユーザー onakaT_Titai
提出日時 2020-03-09 19:57:36
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,484 ms / 2,000 ms
コード長 2,163 bytes
コンパイル時間 1,524 ms
コンパイル使用メモリ 119,232 KB
実行使用メモリ 38,528 KB
最終ジャッジ日時 2024-11-09 00:40:16
合計ジャッジ時間 3,995 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
#include <random>
#include <time.h>
#include <unordered_set>

using namespace std;
using Int = long long;

constexpr double EPS = 1e-10;
constexpr long long MOD = 1000000007;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for (int i = 0;i < 60; i++) {
        if (n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

long long my_mod_pow(long long x, long long n) {
	long long ret = 1;
	for (; n > 0; n >>= 1, x = x * x % MOD) {
		if (n & 1) {
			ret = ret * x % MOD;
		}
	}
	return ret;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

void fastInput() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

vector<long long> Divisor(long long n) {
    vector<long long> ret;
    for(long long i=1; i*i<=n; i++) {
        if(n % i == 0) {
            ret.push_back(i);
            if(i*i!=n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end());
    ret.pop_back();
    return ret;
}

vector<vector<long long>> yakusu;

int main(void) {
    int N; cin >> N;
    vector<int> A(N+1);
    for (int i = 1; i <= N; i++) {
        cin >> A[i];
    }
    
    yakusu = vector<vector<long long>>(300005);
    for (int i = 1; i <= N; i++) {
        yakusu[A[i]] = Divisor(A[i]);
    }

    vector<int> dp(300005);
    for (int i = 1; i <= N; i++) {
        dp[A[i]] = max(dp[A[i]], 1);
        for (int j = 0; j < yakusu[A[i]].size(); j++) {
            dp[A[i]] = max(dp[A[i]], dp[yakusu[A[i]][j]] + 1);
        }
    }
    int ans = 0;
    for (int i = 0; i < 300005; i++) {
        ans = max(ans, dp[i]);
    }
    cout << ans << endl;

}
0