結果

問題 No.390 最長の数列
ユーザー jajagacchijajagacchi
提出日時 2017-01-01 15:47:54
言語 C++11
(gcc 11.4.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 822 bytes
コンパイル時間 570 ms
コンパイル使用メモリ 65,076 KB
実行使用メモリ 9,464 KB
最終ジャッジ日時 2024-04-10 10:14:06
合計ジャッジ時間 3,993 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,812 KB
testcase_01 AC 3 ms
6,944 KB
testcase_02 AC 3 ms
6,944 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 3 ms
6,940 KB
testcase_05 AC 502 ms
6,944 KB
testcase_06 AC 335 ms
9,408 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 3 ms
6,944 KB
testcase_09 AC 3 ms
6,944 KB
testcase_10 AC 369 ms
9,428 KB
testcase_11 AC 368 ms
9,464 KB
testcase_12 AC 366 ms
9,412 KB
testcase_13 AC 264 ms
9,432 KB
testcase_14 AC 143 ms
6,940 KB
testcase_15 RE -
testcase_16 AC 4 ms
7,404 KB
testcase_17 AC 21 ms
8,952 KB
testcase_18 AC 32 ms
9,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>

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]];
	dp[x[0]] = 1;
	int M = 1;
	
	for(int i=1;i<N;i++)
	{
		int max = 1;
		int l=1;
		for(int k=1 ; k<=sqrt(x[i]) ; k++)
		{
			if(X[k]==true && x[i]%k==0)//kはx[i]の約数
			{
				l = dp[k] + 1;
				if(l > max) max = l;
			}
			if(x[i]%k==0 && X[x[i]/k]==true && k!=1)//kはx[i]の約数
			{
				l = dp[x[i]/k] + 1;
				if(l > max) max = l;
			}
		}
		dp[x[i]] = max;

		if(M < dp[x[i]]) M = dp[x[i]];
	}
	std::cout << M << std::endl;

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

	return 0;
}
0