結果

問題 No.979 Longest Divisor Sequence
ユーザー square1001square1001
提出日時 2020-01-31 21:32:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 711 ms / 2,000 ms
コード長 741 bytes
コンパイル時間 712 ms
コンパイル使用メモリ 75,696 KB
実行使用メモリ 49,456 KB
最終ジャッジ日時 2023-10-17 08:49:43
合計ジャッジ時間 4,192 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
4,348 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,348 KB
testcase_10 AC 437 ms
42,856 KB
testcase_11 AC 435 ms
42,856 KB
testcase_12 AC 431 ms
42,856 KB
testcase_13 AC 51 ms
6,852 KB
testcase_14 AC 711 ms
49,456 KB
testcase_15 AC 517 ms
44,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
	int mx = *max_element(A.begin(), A.end());
	vector<vector<int> > g(mx + 1), divs(mx + 1);
	for (int i = 1; i <= mx; ++i) {
		for (int j = i * 2; j <= mx; j += i) {
			divs[j].push_back(i);
		}
	}
	for (int i = 0; i < N; ++i) {
		g[A[i]].push_back(i);
	}
	vector<int> dp(N);
	for (int i = 0; i < N; ++i) {
		for (int j : divs[A[i]]) {
			int ptr = lower_bound(g[j].begin(), g[j].end(), i) - g[j].begin() - 1;
			if (ptr != -1) dp[i] = max(dp[i], dp[g[j][ptr]]);
		}
		++dp[i];
	}
	int ans = *max_element(dp.begin(), dp.end());
	cout << ans << endl;
	return 0;
}
0