結果

問題 No.390 最長の数列
ユーザー startcppstartcpp
提出日時 2016-07-10 16:25:53
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 655 bytes
コンパイル時間 663 ms
コンパイル使用メモリ 58,968 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 12:27:03
合計ジャッジ時間 2,539 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
5,248 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 8 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 8 ms
5,376 KB
testcase_05 AC 38 ms
5,376 KB
testcase_06 AC 610 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 10 ms
5,376 KB
testcase_10 AC 47 ms
5,376 KB
testcase_11 AC 63 ms
5,376 KB
testcase_12 AC 66 ms
5,376 KB
testcase_13 AC 38 ms
5,376 KB
testcase_14 AC 333 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

//ちょっと高速解法O(nlog^2n)
#include <iostream>
#include <algorithm>
using namespace std;

int n;
int x[100000];
int dp[100000];

//返り値:x[id+1]~x[n-1]で作れる良い数列の長さのMax
int f(int id) {
	int ret = 0;
	
	if (dp[id] != -1) { return dp[id]; }
	for (int mul = 2; x[id] * mul <= 1000000; mul++) {
		int next = lower_bound(x, x + n, mul * x[id]) - x;
		if (next < n && x[next] % x[id] == 0) {
			ret = max(ret, 1 + f(next));
		}
	}
	return (dp[id] = ret);
}

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) cin >> x[i];
	sort(x, x + n);
	for (int i = 0; i < n; i++) dp[i] = -1;
	cout << 1 + f(0) << endl;
	return 0;
}
0