結果

問題 No.390 最長の数列
ユーザー kongarishisyamokongarishisyamo
提出日時 2016-07-15 17:30:25
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 715 bytes
コンパイル時間 609 ms
コンパイル使用メモリ 64,616 KB
実行使用メモリ 15,232 KB
最終ジャッジ日時 2024-04-23 01:55:41
合計ジャッジ時間 7,161 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
9,724 KB
testcase_01 AC 4 ms
9,692 KB
testcase_02 AC 3 ms
9,600 KB
testcase_03 AC 3 ms
9,432 KB
testcase_04 AC 3 ms
9,600 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using namespace std;

#define NMAX 100000
#define aMAX 1000000

int x[NMAX];
int memo[aMAX+1];
vector<int> ai[NMAX];

int search(int i){
	int maxn=0;
	if(memo[i]!=-1) return memo[i];
	if(ai[i].size()==0){
		memo[i]=1;
		return 1;
	}
	for(int j=0;j<ai[i].size();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++){
		for(int j=i+1;j<N;j++){
			if(x[j]%x[i]==0){
				ai[i].push_back(j);
			}
		}

	}

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

	cout<<maxn<<endl;
}

0