結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,816 KB
testcase_01 AC 3 ms
6,940 KB
testcase_02 AC 3 ms
6,944 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 3 ms
6,944 KB
testcase_05 AC 500 ms
9,448 KB
testcase_06 AC 336 ms
9,416 KB
testcase_07 AC 3 ms
6,940 KB
testcase_08 AC 6 ms
9,044 KB
testcase_09 AC 5 ms
9,044 KB
testcase_10 AC 367 ms
9,424 KB
testcase_11 AC 367 ms
9,432 KB
testcase_12 AC 367 ms
9,488 KB
testcase_13 AC 263 ms
9,392 KB
testcase_14 AC 144 ms
6,940 KB
testcase_15 RE -
testcase_16 AC 5 ms
9,028 KB
testcase_17 AC 22 ms
9,088 KB
testcase_18 AC 32 ms
9,096 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 = 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;
//				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