結果

問題 No.390 最長の数列
ユーザー jajagacchijajagacchi
提出日時 2017-01-01 06:51:35
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 846 bytes
コンパイル時間 553 ms
コンパイル使用メモリ 66,104 KB
実行使用メモリ 14,484 KB
最終ジャッジ日時 2023-08-22 09:08:37
合計ジャッジ時間 7,346 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
const int INF = 1e9;

int main()
{
	int N; std::cin >> N;
	int *x = new int[N];
	bool *X = new bool[2000000];
	for(int i=0;i<2000000;i++)
	{
		X[i] = false;
	}
	for(int i=0;i<N;i++)
	{
		std::cin >> x[i];
		X[x[i]] = true;
	}
	std::sort(x , x+N);
	int *dp = new int[x[N-1]];
	for(int i=0;i<=x[N-1];i++)
	{
		dp[i] = INF;
	}
	dp[x[0]] = 1;

	int M = 0;
	for(int i=1;i<N;i++)
	{
		int max = 1;
		int l=1;
		for(int k=1 ; k<=x[i]/2 ; k++)
		{
			if(X[k]==true && x[i]%k==0)//kはx[i]の約数
			{
				l = dp[k] + 1;
			}
			if(l > max) max = l;
		}
		dp[x[i]] = max;

		if(M < dp[x[i]]) M = dp[x[i]];
	}
// 	for(int i=0;i<N;i++)
// 	{
// 		printf("dp[%d] = %d\n" , i , dp[x[i]]);
// 	}
	std::cout << M << std::endl;

	delete[] x;
	delete[] dp;
	delete[] X;

	return 0;
}
0