結果

問題 No.979 Longest Divisor Sequence
ユーザー chocoruskchocorusk
提出日時 2020-01-31 22:18:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 546 ms / 2,000 ms
コード長 988 bytes
コンパイル時間 1,054 ms
コンパイル使用メモリ 113,816 KB
実行使用メモリ 38,600 KB
最終ジャッジ日時 2023-10-17 10:14:38
合計ジャッジ時間 8,873 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 409 ms
37,432 KB
testcase_01 AC 411 ms
37,432 KB
testcase_02 AC 409 ms
37,432 KB
testcase_03 AC 390 ms
37,432 KB
testcase_04 AC 391 ms
37,432 KB
testcase_05 AC 401 ms
37,432 KB
testcase_06 AC 417 ms
37,432 KB
testcase_07 AC 386 ms
37,432 KB
testcase_08 AC 382 ms
37,432 KB
testcase_09 AC 378 ms
37,432 KB
testcase_10 AC 398 ms
37,444 KB
testcase_11 AC 435 ms
37,444 KB
testcase_12 AC 430 ms
37,444 KB
testcase_13 AC 475 ms
38,600 KB
testcase_14 AC 546 ms
38,600 KB
testcase_15 AC 479 ms
37,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
int main()
{
	int n;
	cin>>n;
	int a[300030];
	for(int i=0; i<n; i++){
		cin>>a[i];
	}
	vector<int> g[300030];
	for(int d=1; d<=300000; d++){
		for(int i=2; i<=300000/d; i++){
			g[d*i].push_back(d);
		}
	}
	int dp[300030]={};
	for(int i=0; i<n; i++){
	    dp[a[i]]=1;
		for(auto y:g[a[i]]){
			dp[a[i]]=max(dp[a[i]], dp[y]+1);
		}
	}
	int ans=1;
	for(int i=1; i<=300000; i++) ans=max(ans, dp[i]);
	cout<<ans<<endl;
	return 0;
}
0