結果

問題 No.390 最長の数列
ユーザー RIGIHRIGIH
提出日時 2017-07-26 16:36:08
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,073 bytes
コンパイル時間 561 ms
コンパイル使用メモリ 65,320 KB
実行使用メモリ 10,912 KB
最終ジャッジ日時 2024-04-18 00:03:01
合計ジャッジ時間 7,089 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 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 <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define LL long long
#define mass 1000000007
using namespace std;
int keta(int n,int k){return (n/int(pow(10,double(k-1)))) % 10;} //nの下からk桁目
void qsort(int *,int,int);


int main(){
	
	int n;
	cin>>n;
	int *x;
	x=new int[n];
	int *a;
	a=new int[n];
	rep(i,n){
		cin>>x[i];
		a[i]=1;
	}
	if(n>=2) qsort(x,0,n-1);

	int ans=0;

	rep(i,n){
		rep(j,i){
			if(x[j]%x[i]==0){
				a[i]=max(a[i],a[j]+1);
			}
		}
		ans=max(ans,a[i]);
	}
	cout<<ans<<endl;



	delete []x;
	delete []a;
	return 0;


}

void qsort(int *x,int begin,int end){
	int i,j;
	i=begin;
	j=end;
	int z;
	int pivot=x[(i+j)/2];

	while(1){
		while(x[i]>pivot){
			i++;
		}
		while(x[j]<pivot){
			j--;
		}
		if(j<=i){
			break;
		}
		z=x[i];x[i]=x[j];x[j]=z;
		i++;j--;
	}
	if(i-begin>1) qsort(x,begin,i-1);
	if(end-j>1) qsort(x,j+1,end);
}

0