結果

問題 No.390 最長の数列
ユーザー nksk38nksk38
提出日時 2017-08-02 12:18:32
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,129 ms / 5,000 ms
コード長 1,094 bytes
コンパイル時間 1,002 ms
コンパイル使用メモリ 87,376 KB
実行使用メモリ 7,808 KB
最終ジャッジ日時 2024-04-19 13:26:03
合計ジャッジ時間 7,162 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 KB
testcase_01 AC 3 ms
5,248 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 1,129 ms
5,376 KB
testcase_06 AC 750 ms
7,808 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 808 ms
7,680 KB
testcase_11 AC 807 ms
7,680 KB
testcase_12 AC 807 ms
7,808 KB
testcase_13 AC 577 ms
7,680 KB
testcase_14 AC 301 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 4 ms
5,376 KB
testcase_17 AC 42 ms
7,296 KB
testcase_18 AC 64 ms
7,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, string> pls;

#define MAX_N 1000000

int n;
int x[100010];
int dp[1000010];

vector<ll> enumdiv(ll n) {
	vector<ll> s;
	for (ll i = 1; i*i <= n; i++) {
		if (n % i == 0) {
			s.push_back(i);
			if (i*i != n)
				s.push_back(n / i);
		}
	}
	sort(s.begin(),s.end());
	return s;
}

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[x[i]] = 1;

	for (int i = 1; i < 1000001; i++) {
		if (dp[i]) {
			auto  v = enumdiv(i);
			for (int j : v) {
				if (j != i)
					dp[i] = max(dp[i],dp[j]+1);
			}
		}
	}

	int ans = 0;
	for (int i = 0; i < n; i++)
		ans = max(ans,dp[x[i]]);
	cout << ans << endl;
	return 0;
}
0