結果

問題 No.979 Longest Divisor Sequence
ユーザー QCFiumQCFium
提出日時 2020-01-31 22:12:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 541 ms / 2,000 ms
コード長 562 bytes
コンパイル時間 1,631 ms
コンパイル使用メモリ 169,988 KB
実行使用メモリ 6,064 KB
最終ジャッジ日時 2023-10-17 10:04:08
合計ジャッジ時間 3,691 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 3 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 3 ms
4,348 KB
testcase_10 AC 10 ms
4,904 KB
testcase_11 AC 9 ms
4,900 KB
testcase_12 AC 9 ms
4,900 KB
testcase_13 AC 30 ms
4,888 KB
testcase_14 AC 541 ms
6,064 KB
testcase_15 AC 183 ms
5,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int main() {
	int n = ri();
	int a[n];
	for (auto &i : a) i = ri();
	static int max[300001];
	for (int i = 0; i < n; i++) {
		std::vector<int> divs;
		for (int j = 1; j * j <= a[i]; j++) {
			if (a[i] % j == 0) {
				if (j != a[i]) divs.push_back(j);
				if (j > 1) divs.push_back(a[i] / j);
			}
		}
		int cur = 0;
		for (auto j : divs) cur = std::max(cur, max[j]);
		max[a[i]] = std::max(max[a[i]], cur + 1);
	}
	printf("%d\n", *std::max_element(max, max + 300001));
	
  	return 0;
}
0