結果

問題 No.390 最長の数列
ユーザー misora192misora192
提出日時 2020-06-18 08:31:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 48 ms / 5,000 ms
コード長 657 bytes
コンパイル時間 1,520 ms
コンパイル使用メモリ 168,716 KB
実行使用メモリ 7,456 KB
最終ジャッジ日時 2023-09-16 11:58:56
合計ジャッジ時間 2,982 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
6,840 KB
testcase_01 AC 4 ms
6,868 KB
testcase_02 AC 5 ms
6,856 KB
testcase_03 AC 5 ms
6,924 KB
testcase_04 AC 6 ms
6,880 KB
testcase_05 AC 19 ms
7,444 KB
testcase_06 AC 35 ms
7,456 KB
testcase_07 AC 4 ms
6,852 KB
testcase_08 AC 3 ms
6,924 KB
testcase_09 AC 4 ms
6,996 KB
testcase_10 AC 24 ms
7,380 KB
testcase_11 AC 25 ms
7,404 KB
testcase_12 AC 24 ms
7,436 KB
testcase_13 AC 18 ms
7,100 KB
testcase_14 AC 48 ms
7,368 KB
testcase_15 AC 4 ms
6,908 KB
testcase_16 AC 4 ms
6,976 KB
testcase_17 AC 5 ms
6,924 KB
testcase_18 AC 5 ms
6,920 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n;
	cin >> n;

	vector<int> x(n);
	rep(i, n) cin >> x[i];
	sort(x.begin(), x.end());

	int max_x = 1010101;
	vector<int> dp(max_x, 1);

	rep(i, n){
		int y = x[i];
		for(int j = 2 * y; j < max_x; j += y) chmax(dp[j], dp[y] + 1);
	}

	int ans = 0;
	rep(i, n) chmax(ans, dp[x[i]]);
	cout << ans << endl;
}
0