結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
7,236 KB
testcase_01 AC 5 ms
7,216 KB
testcase_02 AC 6 ms
7,152 KB
testcase_03 AC 5 ms
7,140 KB
testcase_04 AC 6 ms
7,200 KB
testcase_05 AC 37 ms
7,256 KB
testcase_06 AC 54 ms
7,140 KB
testcase_07 AC 5 ms
7,076 KB
testcase_08 AC 4 ms
7,144 KB
testcase_09 AC 5 ms
7,196 KB
testcase_10 AC 47 ms
7,168 KB
testcase_11 AC 47 ms
7,168 KB
testcase_12 AC 44 ms
7,168 KB
testcase_13 AC 35 ms
7,140 KB
testcase_14 AC 58 ms
7,080 KB
testcase_15 AC 4 ms
7,140 KB
testcase_16 AC 4 ms
7,100 KB
testcase_17 AC 6 ms
7,076 KB
testcase_18 AC 7 ms
7,192 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);

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> 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;
	return 0;
}
0