結果

問題 No.390 最長の数列
ユーザー kongarishisyamokongarishisyamo
提出日時 2016-07-15 17:38:34
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 766 bytes
コンパイル時間 682 ms
コンパイル使用メモリ 66,780 KB
実行使用メモリ 11,356 KB
最終ジャッジ日時 2024-04-23 01:56:10
合計ジャッジ時間 2,334 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,632 KB
testcase_01 AC 4 ms
9,676 KB
testcase_02 AC 3 ms
8,268 KB
testcase_03 AC 3 ms
7,632 KB
testcase_04 AC 3 ms
8,268 KB
testcase_05 AC 39 ms
8,656 KB
testcase_06 WA -
testcase_07 AC 3 ms
7,884 KB
testcase_08 AC 3 ms
8,400 KB
testcase_09 AC 3 ms
7,368 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 72 ms
7,916 KB
testcase_14 WA -
testcase_15 AC 3 ms
8,012 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>

using namespace std;

#define NMAX 100000
#define aMAX 1000000

int x[NMAX];
int memo[aMAX+1];
int ai[NMAX][30];
int an[NMAX];

int search(int i){
	int maxn=0;
	if(memo[i]!=-1) return memo[i];

	if(an[i]==0){
		memo[i]=1;
		return 1;
	}
	for(int j=0;j<an[i];j++){
		maxn=max(maxn,search(ai[i][j]));
	}
	memo[i]=maxn+1;
	return maxn+1;
}

int main(){

	int N;
	int maxn=-1;

	cin>>N;
	for(int i=0;i<N;i++) cin>>x[i];
	for(int i=0;i<=aMAX;i++) memo[i]=-1;

	sort(x,x+N);

	for(int i=0;i<N;i++){
		if(x[i]>sqrt((double)aMAX)) continue;
		for(int j=i+1;j<N;j++){
			if(x[j]%x[i]==0){
				ai[i][an[i]++]=j;
			}
		}

	}

	for(int i=0;i<N;i++){
		maxn=max(maxn,search(i));
	}

	cout<<maxn<<endl;
}

0