結果

問題 No.390 最長の数列
ユーザー masa
提出日時 2016-07-09 19:29:15
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 52 ms / 5,000 ms
コード長 517 bytes
コンパイル時間 592 ms
コンパイル使用メモリ 70,528 KB
実行使用メモリ 7,296 KB
最終ジャッジ日時 2024-10-02 10:46:41
合計ジャッジ時間 1,522 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

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