結果

問題 No.390 最長の数列
ユーザー masamasa
提出日時 2016-07-09 19:33:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 36 ms / 5,000 ms
コード長 616 bytes
コンパイル時間 487 ms
コンパイル使用メモリ 68,936 KB
実行使用メモリ 7,808 KB
最終ジャッジ日時 2024-04-10 09:01:13
合計ジャッジ時間 1,384 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
7,592 KB
testcase_01 AC 5 ms
7,684 KB
testcase_02 AC 5 ms
7,540 KB
testcase_03 AC 4 ms
7,748 KB
testcase_04 AC 5 ms
7,512 KB
testcase_05 AC 13 ms
7,724 KB
testcase_06 AC 32 ms
7,788 KB
testcase_07 AC 5 ms
7,632 KB
testcase_08 AC 3 ms
7,692 KB
testcase_09 AC 4 ms
7,780 KB
testcase_10 AC 19 ms
7,756 KB
testcase_11 AC 19 ms
7,528 KB
testcase_12 AC 19 ms
7,808 KB
testcase_13 AC 16 ms
7,784 KB
testcase_14 AC 36 ms
7,600 KB
testcase_15 AC 4 ms
7,584 KB
testcase_16 AC 3 ms
7,460 KB
testcase_17 AC 4 ms
7,672 KB
testcase_18 AC 4 ms
7,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

const int X_MAX = 1e6;

int main() {
	int n, x;
	// vector<int> nums(X_MAX + 1, 0);
	int nums[X_MAX + 1] = {0};

	// cin >> n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		// cin >> x;
		scanf("%d", &x);
		nums[x] = 1;
	}

	int ans = 0;
	for (int i = X_MAX; i >= 1; i--) {
		if (nums[i] == 0) {
			continue;
		}

		for (int j = i * 2; j <= X_MAX; j += i) {
			nums[i] = max(nums[i], nums[j] + 1);
		}
		ans = max(ans, nums[i]);
	}
	// cout << ans << endl;
	printf("%d\n", ans);
	return 0;
}
0