結果

問題 No.390 最長の数列
ユーザー rodearodea
提出日時 2017-12-22 15:57:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 829 bytes
コンパイル時間 772 ms
コンパイル使用メモリ 78,616 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-22 21:17:35
合計ジャッジ時間 3,972 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 AC 2 ms
4,380 KB
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 AC 288 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

vector<long long> divisor(long long n)
{
	vector<long long> s;

	for (long long 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()
{
	int n, i, x[100000], dp[100000];

	cin >> n;

	for (i = 1; i <= n; i++)
	{
		cin >> x[i];
	}

	sort(x + 1, x + n + 1);

	for (i = 1; i <= x[n]; i++)
	{
		dp[i] = 0;
	}

	for (i = 1; i <= n; i++)
	{
		dp[x[i]] = 1;
	}

	for (i = 1; i <= x[n]; i++)
	{
		if (dp[i]>0)
		{
			auto v = divisor(i);

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

	int ans = 0;
	for (i = 1; i <= n; i++)
	{
		ans = max(ans, dp[x[i]]);
	}

	cout << ans << endl;
}
0