結果

問題 No.979 Longest Divisor Sequence
ユーザー leaf_1415leaf_1415
提出日時 2020-01-31 21:51:25
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 541 ms / 2,000 ms
コード長 820 bytes
コンパイル時間 1,338 ms
コンパイル使用メモリ 63,320 KB
実行使用メモリ 61,264 KB
最終ジャッジ日時 2023-10-17 09:24:56
合計ジャッジ時間 9,381 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 433 ms
57,448 KB
testcase_01 AC 452 ms
57,448 KB
testcase_02 AC 453 ms
57,448 KB
testcase_03 AC 452 ms
57,448 KB
testcase_04 AC 471 ms
59,492 KB
testcase_05 AC 395 ms
57,448 KB
testcase_06 AC 397 ms
57,448 KB
testcase_07 AC 388 ms
57,448 KB
testcase_08 AC 404 ms
59,492 KB
testcase_09 AC 405 ms
57,448 KB
testcase_10 AC 407 ms
57,848 KB
testcase_11 AC 407 ms
57,848 KB
testcase_12 AC 404 ms
57,848 KB
testcase_13 AC 426 ms
61,264 KB
testcase_14 AC 541 ms
61,264 KB
testcase_15 AC 495 ms
58,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <set>
#define llint long long
#define mod 1000000007

using namespace std;

llint n;
llint a[300005];
vector<llint> vec[300005];
llint pred[300005];
llint dp[300005];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	
	for(int i = 1; i <= 300000; i++){
		for(int j = 2*i; j <= 300000; j += i){
			vec[j].push_back(i);
		}
	}
	
	for(int i = 1; i <= n; i++){
		dp[i] = 1;
		for(int j = 0; j < vec[a[i]].size(); j++){
			llint x = vec[a[i]][j];
			if(pred[x] == 0) continue;
			dp[i] = max(dp[i], dp[pred[x]]+1);
		}
		pred[a[i]] = i;
	}
	
	//for(int i = 1; i <= n; i++) cout << dp[i] << " "; cout << endl;
	
	llint ans = 0;
	for(int i = 1; i <= n; i++) ans = max(ans, dp[i]);
	cout << ans << endl;
	
	return 0;
}
0