結果

問題 No.390 最長の数列
ユーザー femtofemto
提出日時 2016-07-08 23:16:05
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 51 ms / 5,000 ms
コード長 610 bytes
コンパイル時間 633 ms
コンパイル使用メモリ 69,492 KB
実行使用メモリ 8,696 KB
最終ジャッジ日時 2024-04-10 08:51:47
合計ジャッジ時間 1,722 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
7,304 KB
testcase_01 AC 4 ms
7,516 KB
testcase_02 AC 4 ms
7,480 KB
testcase_03 AC 4 ms
7,092 KB
testcase_04 AC 4 ms
7,648 KB
testcase_05 AC 21 ms
7,728 KB
testcase_06 AC 51 ms
8,696 KB
testcase_07 AC 5 ms
7,192 KB
testcase_08 AC 4 ms
7,540 KB
testcase_09 AC 6 ms
7,176 KB
testcase_10 AC 25 ms
8,608 KB
testcase_11 AC 26 ms
8,672 KB
testcase_12 AC 26 ms
8,668 KB
testcase_13 AC 17 ms
8,532 KB
testcase_14 AC 22 ms
7,584 KB
testcase_15 AC 4 ms
7,336 KB
testcase_16 AC 4 ms
7,680 KB
testcase_17 AC 6 ms
8,268 KB
testcase_18 AC 7 ms
8,240 KB
権限があれば一括ダウンロードができます

ソースコード

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