結果

問題 No.390 最長の数列
ユーザー yukkuriesuyukkuriesu
提出日時 2018-12-06 21:52:30
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 69 ms / 5,000 ms
コード長 1,601 bytes
コンパイル時間 1,817 ms
コンパイル使用メモリ 146,260 KB
実行使用メモリ 7,944 KB
最終ジャッジ日時 2023-10-12 02:50:50
合計ジャッジ時間 3,252 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
5,324 KB
testcase_01 AC 5 ms
5,476 KB
testcase_02 AC 6 ms
5,324 KB
testcase_03 AC 5 ms
5,472 KB
testcase_04 AC 7 ms
5,356 KB
testcase_05 AC 39 ms
5,564 KB
testcase_06 AC 69 ms
7,944 KB
testcase_07 AC 5 ms
5,472 KB
testcase_08 AC 3 ms
5,400 KB
testcase_09 AC 5 ms
5,344 KB
testcase_10 AC 44 ms
7,656 KB
testcase_11 AC 44 ms
7,592 KB
testcase_12 AC 43 ms
7,768 KB
testcase_13 AC 33 ms
7,748 KB
testcase_14 AC 57 ms
6,296 KB
testcase_15 AC 4 ms
5,420 KB
testcase_16 AC 3 ms
5,588 KB
testcase_17 AC 6 ms
7,436 KB
testcase_18 AC 7 ms
7,396 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define rep(i,N) repf(i,0,N)
#define reps(i,N) repfs(i,0,N)
#define repf(i,a,b) for(int i=a;i<b;i++)
#define repfs(i,a,b) for(int i=a+1;i<=b;i++)
#define repr(i,N) for(int i=N-1;i>=0;i--)
#define reprs(i,N) for(int i=N;i>0;i--)

#define d(a) if(isDebugMode) cout<<#a<<"="<<a<<"."
#define d2(a,b) if(isDebugMode) cout<<#a<<"="<<a<<","<<#b<<"="<<b<<"."
#define d3(a,b,c) if(isDebugMode) cout<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<"."
#define d4(a,b,c,d) if(isDebugMode) cout<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<","<<#d<<"="<<d<<"."
#define da(arr,N){if(isDebugMode){rep(i,N){if(arr[i]==INF)printf("INF ");else cout<<arr[i]<<" ";} cout<<endl;}}
#define da2(arr,N,M){if(isDebugMode)rep(i,N){rep(j,M){if(arr[i][j]==INF)printf(" INF");else printf(" %3d",arr[i][j]);}cout<<endl;}}
#define pb push_back
#define pob pop_back

auto chmax =[](int &a,int b){ a = max(a, b);};
auto chmin =[](int &a,int b){ a = min(a, b);};

typedef long long ll;
typedef pair<int,int> P;
const int INF = 100000000;
const int MOD = 1000000007;
const int dx[4] = { 0, 1, 0,-1};
const int dy[4] = { 1, 0,-1, 0};

bool isDebugMode=1;
//--------------------------------------//
int n;
int x[100000];

#define MAX_X 1000000
int dp[1000001];
void solve(){
	sort(x,x+n);
	rep(i, n){
		dp[x[i]]=1;
	}
	rep(i,n){
		if(dp[x[i]] <= 0) continue;
		for(int j=x[i]*2;j<=MAX_X;j+=x[i]){
			if(dp[j]>=1)
				chmax(dp[j],dp[x[i]]+1);
		}
	}
	int m=0;
	reps(j,1000000){
		chmax(m,dp[j]);
	}
	cout<<m<<endl;
}

int main(){
	cin>>n;
	rep(i,n) {
		cin>>x[i];
	}
	solve();
	return 0;
}
0