結果

問題 No.390 最長の数列
ユーザー jajagacchijajagacchi
提出日時 2017-01-01 15:13:17
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,059 bytes
コンパイル時間 732 ms
コンパイル使用メモリ 66,248 KB
実行使用メモリ 9,452 KB
最終ジャッジ日時 2023-08-22 09:13:30
合計ジャッジ時間 5,619 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,864 KB
testcase_01 AC 4 ms
4,944 KB
testcase_02 AC 4 ms
4,860 KB
testcase_03 AC 3 ms
4,880 KB
testcase_04 AC 3 ms
4,816 KB
testcase_05 AC 745 ms
9,256 KB
testcase_06 AC 450 ms
9,360 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 6 ms
8,896 KB
testcase_10 AC 525 ms
9,452 KB
testcase_11 AC 523 ms
9,364 KB
testcase_12 AC 523 ms
9,412 KB
testcase_13 AC 391 ms
9,236 KB
testcase_14 AC 193 ms
5,728 KB
testcase_15 RE -
testcase_16 AC 6 ms
8,756 KB
testcase_17 AC 30 ms
9,344 KB
testcase_18 AC 45 ms
8,996 KB
権限があれば一括ダウンロードができます

ソースコード

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<=sqrt(x[i]) ; k++)
		{
			if(X[k]==true && x[i]%k==0)//kはx[i]の約数
			{
				l = dp[k] + 1;
//				printf("k=%d i=%d\n",k,i);
				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;
//				printf("k=%d , x/k=%d , i=%d\n",k,x[i]/k,i);
				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" , x[i] , dp[x[i]]);
// 	}
	std::cout << M << std::endl;

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

	return 0;
}
0