結果
| 問題 | 
                            No.390 最長の数列
                             | 
                    
| コンテスト | |
| ユーザー | 
                             kongarishisyamo
                         | 
                    
| 提出日時 | 2016-07-15 17:35:27 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 740 bytes | 
| コンパイル時間 | 522 ms | 
| コンパイル使用メモリ | 62,196 KB | 
| 実行使用メモリ | 13,640 KB | 
| 最終ジャッジ日時 | 2024-10-15 01:12:51 | 
| 合計ジャッジ時間 | 7,032 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 1 TLE * 1 -- * 13 | 
ソースコード
#include<iostream>
#include<algorithm>
#include<vector>
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]*x[i]>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;
}
            
            
            
        
            
kongarishisyamo