結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:43:23: 警告: iteration 99999 invokes undefined behavior [-Waggressive-loop-optimizations]
   43 |                 dp[i] = 0;
      |                 ~~~~~~^~~
main.cpp:41:23: 備考: within this loop
   41 |         for (i = 1; i <= 100000; i++)
      |                     ~~^~~~~~~~~
main.cpp:43:23: 警告: ‘void* __builtin_memset(void*, int, long unsigned int)’ writing 400000 bytes into a region of size 399996 overflows the destination [-Wstringop-overflow=]
   43 |                 dp[i] = 0;
      |                 ~~~~~~^~~
main.cpp:30:30: 備考: at offset 4 into destination object ‘dp’ of size 400000
   30 |         int n, i, x[100000], dp[100000];
      |                              ^~

ソースコード

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 <= 100000; i++)
	{
		dp[i] = 0;
	}

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

	for (i = 1; i <= 100000; i++)
	{
		if (dp[i])
		{
			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