結果

問題 No.390 最長の数列
ユーザー femtofemto
提出日時 2016-07-08 23:05:48
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 622 bytes
コンパイル時間 556 ms
コンパイル使用メモリ 69,468 KB
実行使用メモリ 8,704 KB
最終ジャッジ日時 2024-04-21 07:45:51
合計ジャッジ時間 1,429 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
7,296 KB
testcase_01 AC 6 ms
7,296 KB
testcase_02 AC 5 ms
7,296 KB
testcase_03 AC 6 ms
7,296 KB
testcase_04 WA -
testcase_05 AC 22 ms
7,936 KB
testcase_06 AC 15 ms
8,576 KB
testcase_07 AC 4 ms
7,296 KB
testcase_08 AC 5 ms
7,424 KB
testcase_09 AC 5 ms
7,296 KB
testcase_10 WA -
testcase_11 AC 23 ms
8,576 KB
testcase_12 WA -
testcase_13 AC 17 ms
8,576 KB
testcase_14 AC 21 ms
7,808 KB
testcase_15 AC 5 ms
7,296 KB
testcase_16 AC 5 ms
7,424 KB
testcase_17 AC 7 ms
8,320 KB
testcase_18 AC 7 ms
8,320 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);
				break;
			}
		}
	}
	cout << *max_element(dp, dp + 1000010) << endl;
}
0