結果

問題 No.390 最長の数列
ユーザー pekempeypekempey
提出日時 2016-07-08 22:47:41
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,116 ms / 5,000 ms
コード長 664 bytes
コンパイル時間 1,427 ms
コンパイル使用メモリ 166,068 KB
実行使用メモリ 7,808 KB
最終ジャッジ日時 2024-04-10 08:48:22
合計ジャッジ時間 7,447 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,816 KB
testcase_01 AC 3 ms
6,944 KB
testcase_02 AC 3 ms
6,940 KB
testcase_03 AC 3 ms
6,944 KB
testcase_04 AC 3 ms
6,940 KB
testcase_05 AC 1,116 ms
6,940 KB
testcase_06 AC 735 ms
7,808 KB
testcase_07 AC 3 ms
6,944 KB
testcase_08 AC 3 ms
6,944 KB
testcase_09 AC 3 ms
6,940 KB
testcase_10 AC 789 ms
7,628 KB
testcase_11 AC 791 ms
7,808 KB
testcase_12 AC 789 ms
7,628 KB
testcase_13 AC 564 ms
7,680 KB
testcase_14 AC 286 ms
6,940 KB
testcase_15 AC 3 ms
6,940 KB
testcase_16 AC 4 ms
6,944 KB
testcase_17 AC 42 ms
7,504 KB
testcase_18 AC 63 ms
7,424 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:20:42: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   20 |         for (int i = 0; i < n; i++) scanf("%d", &x[i]);
      |                                     ~~~~~^~~~~~~~~~~~~

ソースコード

diff #

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

int n;
int x[101010];
int dp[1010101];

vector<long long> divisors(long long n) {
	vector<long long> result;
	for (long long i = 1; i * i <= n; i++) if (n % i == 0) {
		result.push_back(i);
		if (i != n / i) result.push_back(n / i);
	}
	sort(result.begin(), result.end());
	return result;
}

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) scanf("%d", &x[i]);
	sort(x, x + n);

	for (int i = 0; i < n; i++) {
		dp[x[i]] = max(dp[x[i]], 1);
		for (int d : divisors(x[i])) {
			if (d < x[i]) {
				dp[x[i]] = max(dp[x[i]], dp[d] + 1);
			}
		}
	}

	int ans = *max_element(dp, dp + 1010101);
	cout << ans << endl;
}
0