結果

問題 No.390 最長の数列
ユーザー rodearodea
提出日時 2017-12-22 16:13:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,085 ms / 5,000 ms
コード長 783 bytes
コンパイル時間 862 ms
コンパイル使用メモリ 78,788 KB
実行使用メモリ 7,864 KB
最終ジャッジ日時 2023-08-22 21:19:21
合計ジャッジ時間 7,017 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,380 KB
testcase_01 AC 2 ms
4,504 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 1,085 ms
4,388 KB
testcase_06 AC 704 ms
7,644 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 770 ms
7,656 KB
testcase_11 AC 780 ms
7,864 KB
testcase_12 AC 772 ms
7,736 KB
testcase_13 AC 561 ms
7,568 KB
testcase_14 AC 286 ms
6,000 KB
testcase_15 AC 3 ms
4,384 KB
testcase_16 AC 4 ms
5,596 KB
testcase_17 AC 38 ms
7,272 KB
testcase_18 AC 61 ms
7,380 KB
権限があれば一括ダウンロードができます

ソースコード

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[101010], dp[1010101];

	cin >> n;

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

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

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

	for (i = 1; i <= 1000001; i++)
	{
		if (dp[i])
		{
			auto v = divisor(i);

			for (auto 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