結果

問題 No.390 最長の数列
ユーザー kurenai3110kurenai3110
提出日時 2016-08-19 07:58:45
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 67 ms / 5,000 ms
コード長 496 bytes
コンパイル時間 705 ms
コンパイル使用メモリ 65,300 KB
実行使用メモリ 7,552 KB
最終ジャッジ日時 2024-04-10 10:05:42
合計ジャッジ時間 1,828 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
7,424 KB
testcase_01 AC 8 ms
7,168 KB
testcase_02 AC 9 ms
7,424 KB
testcase_03 AC 9 ms
7,424 KB
testcase_04 AC 9 ms
7,424 KB
testcase_05 AC 42 ms
6,940 KB
testcase_06 AC 57 ms
7,552 KB
testcase_07 AC 8 ms
7,296 KB
testcase_08 AC 3 ms
6,940 KB
testcase_09 AC 8 ms
7,296 KB
testcase_10 AC 48 ms
7,424 KB
testcase_11 AC 49 ms
7,552 KB
testcase_12 AC 48 ms
7,436 KB
testcase_13 AC 38 ms
7,436 KB
testcase_14 AC 67 ms
7,552 KB
testcase_15 AC 4 ms
6,940 KB
testcase_16 AC 4 ms
6,948 KB
testcase_17 AC 9 ms
7,424 KB
testcase_18 AC 10 ms
7,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)

int DP[1000001];

int main() {
	int n;
	cin >> n;
	vector<int> x;
	x.resize(n);
	rep(i, n) {
		cin >> x[i];
	}
	sort(x.begin(), x.end());

	rep(i, n) {
		int resource = DP[x[i]];
		for (int j = x[i]; j < 1000001;j+=x[i]) {
			DP[j] = max(DP[j],resource+1);
		}
	}

	int mx = 0;
	for (int i = 0; i < 1000001; i++) {
		mx = max(mx, DP[i]);
	}

	cout << mx << endl;

	return 0;
}
0