結果

問題 No.390 最長の数列
ユーザー mogurockermogurocker
提出日時 2017-10-18 01:20:57
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 34 ms / 5,000 ms
コード長 630 bytes
コンパイル時間 3,369 ms
コンパイル使用メモリ 148,092 KB
実行使用メモリ 7,540 KB
最終ジャッジ日時 2023-08-11 14:54:01
合計ジャッジ時間 4,209 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 19 ms
4,376 KB
testcase_06 AC 34 ms
7,268 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 8 ms
7,540 KB
testcase_10 AC 28 ms
7,356 KB
testcase_11 AC 26 ms
7,296 KB
testcase_12 AC 28 ms
7,276 KB
testcase_13 AC 19 ms
7,344 KB
testcase_14 AC 18 ms
4,384 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 3 ms
4,516 KB
testcase_17 AC 5 ms
7,304 KB
testcase_18 AC 6 ms
7,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;
typedef pair<int, int> P;

int n, dp[1000005];

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n;
	vector<int> x(n);
	FOR(i, n) {
		cin >> x[i];
		dp[x[i]]++;
	}
	sort(ALL(x));
	int ma = 1;
	FOR(i, n) {
		for (int j = 2*x[i]; j <= x.back(); j += x[i]) dp[j] = max(dp[j], dp[x[i]] + 1);
		ma = max(ma, dp[x[i]]);
	}
	cout << ma << endl;
	return 0;
}


0