結果

問題 No.390 最長の数列
ユーザー kkslucy1kkslucy1
提出日時 2018-03-21 06:27:11
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 527 ms / 5,000 ms
コード長 637 bytes
コンパイル時間 1,297 ms
コンパイル使用メモリ 154,624 KB
実行使用メモリ 7,500 KB
最終ジャッジ日時 2023-09-07 00:44:11
合計ジャッジ時間 4,835 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 444 ms
4,380 KB
testcase_06 AC 527 ms
7,400 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 350 ms
7,360 KB
testcase_11 AC 350 ms
7,208 KB
testcase_12 AC 351 ms
7,260 KB
testcase_13 AC 187 ms
7,208 KB
testcase_14 AC 179 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 19 ms
7,500 KB
testcase_18 AC 29 ms
7,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int dp[1000010] = { };

int main() {
	int n;
	cin >> n;
	vector<int> x(n);
	for (int i = 0;i < n;i++) {
		cin >> x[i];
	}
	sort(x.begin(), x.end());

	for (int i = 0;i < n;i++){
		dp[x[i]] = 1;
	}
	for (int i = 0;i < n;i++) {
		set<int> s;
		for (int j = 1;j*j <= x[i];j++) {
			if (x[i] % j == 0) {
				s.insert(x[i] / j);
				s.insert(j);
			}
		}
		for (auto j : s) {
			if (x[i] <= j) {
				continue;
			}
			if (dp[j] != 0) {
				dp[x[i]] = max(dp[x[i]], dp[j] + 1);
			}
		}
	}
	int ma = 1;
	for (int i = 0;i < n;i++) {
		ma = max(ma, dp[x[i]]);
	}
	cout << ma << endl;


	return 0;
}
0