結果

問題 No.979 Longest Divisor Sequence
ユーザー milanis48663220milanis48663220
提出日時 2020-07-02 01:09:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 541 ms / 2,000 ms
コード長 896 bytes
コンパイル時間 802 ms
コンパイル使用メモリ 86,284 KB
実行使用メモリ 5,724 KB
最終ジャッジ日時 2023-10-12 09:55:28
合計ジャッジ時間 3,163 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 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 2 ms
4,352 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 9 ms
4,560 KB
testcase_11 AC 9 ms
4,624 KB
testcase_12 AC 9 ms
4,568 KB
testcase_13 AC 29 ms
4,560 KB
testcase_14 AC 541 ms
5,724 KB
testcase_15 AC 182 ms
5,012 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using namespace std;
typedef long long ll;

template <typename T>
vector<T> divs(T N) {
	vector<T> ans;
	for (int i = 1; i * i <= N; i++) {
		if (N % i == 0) {
		ans.push_back(i);
		if (i * i != N) ans.push_back(N / i);
		}
	}
	return ans;
}

int N;
int A[300000];

int dp[300005];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N;
    for(int i = 0; i < N; i++) cin >> A[i];
    for(int i = 0; i < N; i++){
        auto v = divs<int>(A[i]);
        dp[A[i]] = max(dp[A[i]], 1);
        for(int j : v){
            if(j == A[i]) continue;
            dp[A[i]] = max(dp[j]+1, dp[A[i]]);
        }
    }
    int ans = 0;
    for(int i = 1; i <= 300000; i++) ans = max(ans, dp[i]);
    cout << ans << endl;
}
0