結果

問題 No.390 最長の数列
ユーザー vjudge1
提出日時 2025-04-18 00:04:59
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 52 ms / 5,000 ms
コード長 514 bytes
コンパイル時間 4,037 ms
コンパイル使用メモリ 276,152 KB
実行使用メモリ 13,024 KB
最終ジャッジ日時 2025-04-18 00:05:04
合計ジャッジ時間 5,430 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long

const int N = 1000010;

int n, a[N], dp[N];

signed main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
	cin >> n;
	for (int i = 1; i <= n; i ++ ) cin >> a[i];
	sort(a + 1, a + n + 1);
	for (int i = 1; i <= n; i ++ ) {
		dp[a[i]] = max(dp[a[i]], 1ll);
		for (int j = a[i] + a[i]; j < N; j += a[i])
			dp[j] = max(dp[j], dp[a[i]] + 1);
	}
	int res = 0;
	for (int i = 1; i <= n; i ++ ) res = max(res, dp[a[i]]);
	cout << res;
	return 0;
}
0