結果

問題 No.390 最長の数列
ユーザー jajagacchijajagacchi
提出日時 2017-01-03 06:59:38
言語 C++11
(gcc 11.4.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 934 bytes
コンパイル時間 634 ms
コンパイル使用メモリ 69,060 KB
実行使用メモリ 9,420 KB
最終ジャッジ日時 2024-04-10 10:17:20
合計ジャッジ時間 3,684 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 3 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 3 ms
6,944 KB
testcase_05 AC 422 ms
6,940 KB
testcase_06 AC 299 ms
9,420 KB
testcase_07 AC 3 ms
6,940 KB
testcase_08 AC 3 ms
6,940 KB
testcase_09 AC 3 ms
6,940 KB
testcase_10 AC 317 ms
9,396 KB
testcase_11 AC 307 ms
9,376 KB
testcase_12 AC 316 ms
9,376 KB
testcase_13 AC 215 ms
9,292 KB
testcase_14 AC 140 ms
6,940 KB
testcase_15 RE -
testcase_16 AC 4 ms
7,304 KB
testcase_17 AC 19 ms
9,088 KB
testcase_18 AC 27 ms
9,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

std::vector<int> enum_div(int n)//nの約数を列挙
{
	std::vector<int> ret;
	for(int i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i!=1 && i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}

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;
		std::vector<int> div = enum_div(x[i]);
		for(auto k : div)
		{
			if(X[k])
			{
				l = dp[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