結果

問題 No.390 最長の数列
ユーザー tabataba
提出日時 2017-05-19 06:28:28
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 54 ms / 5,000 ms
コード長 685 bytes
コンパイル時間 975 ms
コンパイル使用メモリ 114,144 KB
実行使用メモリ 7,168 KB
最終ジャッジ日時 2024-04-10 10:20:49
合計ジャッジ時間 2,043 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 24 ms
7,108 KB
testcase_06 AC 54 ms
7,168 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 5 ms
6,940 KB
testcase_09 AC 6 ms
6,944 KB
testcase_10 AC 28 ms
7,064 KB
testcase_11 AC 29 ms
6,992 KB
testcase_12 AC 28 ms
7,104 KB
testcase_13 AC 20 ms
6,940 KB
testcase_14 AC 22 ms
6,940 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 5 ms
6,944 KB
testcase_17 AC 6 ms
6,944 KB
testcase_18 AC 7 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <random>
#include <vector>
#include <algorithm>
#include <array>
#include <functional>
#include <utility>
#include <regex>
#include <tuple>
#include <map>
#include <set>

using namespace std;

int main(){
	int64_t n;
	-scanf("%ld",&n);
	vector<int> x(n);
	for(int i=0;i<n;i++){
		-scanf("%d",&x[i]);
	}
	sort(x.begin(),x.end());
	int64_t m=*(x.end()-1)+1;
	vector<int> d(m);
	for_each(x.begin(),x.end(),[&d](int i){
		d[i]++;
	});
	for(int i=0;i<n;i++){
		for(int j=x[i]*2;j<m;j+=x[i]){
			if(d[j]){
				d[j]=max(d[j],d[x[i]]+1);
			}
		}
	}
	printf("%d\n",*max_element(d.begin(),d.end()));
	return 0;
}
0