結果

問題 No.390 最長の数列
ユーザー femtofemto
提出日時 2016-07-08 23:16:05
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 52 ms / 5,000 ms
コード長 610 bytes
コンパイル時間 934 ms
コンパイル使用メモリ 69,588 KB
実行使用メモリ 8,576 KB
最終ジャッジ日時 2024-10-02 10:35:36
合計ジャッジ時間 1,987 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
using namespace std;

bool exist[1000010];
int dp[1000010];
int x[100000];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;
	for(int i = 0; i < N; i++) {
		cin >> x[i];
		exist[x[i]] = true;
	}

	sort(x, x + N);
	int M = x[N - 1];
	fill(dp, dp + 1000010, 1);
	for(int i = 0; i < N; i++) {
		for(int j = 2; x[i] * j <= M; j++) {
			if(exist[x[i] * j]) {
				dp[x[i] * j] = max(dp[x[i] * j], dp[x[i]] + 1);
			}
		}
	}
	cout << *max_element(dp, dp + 1000010) << endl;
}
0