結果

問題 No.390 最長の数列
ユーザー 夜
提出日時 2021-02-04 21:00:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 346 ms / 5,000 ms
コード長 832 bytes
コンパイル時間 804 ms
コンパイル使用メモリ 94,088 KB
実行使用メモリ 7,796 KB
最終ジャッジ日時 2023-09-13 17:42:49
合計ジャッジ時間 3,547 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,376 KB
testcase_01 AC 3 ms
4,376 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 346 ms
4,380 KB
testcase_06 AC 242 ms
7,636 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 256 ms
7,796 KB
testcase_11 AC 257 ms
7,632 KB
testcase_12 AC 257 ms
7,652 KB
testcase_13 AC 184 ms
7,616 KB
testcase_14 AC 109 ms
4,428 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 18 ms
7,340 KB
testcase_18 AC 25 ms
7,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int co[1000010] = {};
int x[100010];
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}
	sort(x, x + n);
	for (int i = 0; i < n; i++) {
		int m = 1;
		for (int j = 1; j * j <= x[i]; j++) {
			if (x[i] % j == 0) {
				if (x[i] != 1 && m < co[j] + 1) {
					m = co[j] + 1;
				}
				if (j != 1 && m < co[x[i] / j] + 1) {
					m = co[x[i] / j] + 1;
				}
			}
		}
		co[x[i]] = max(co[x[i]], m);
	}
	int ans = 0;
	for (int i = 1; i < 1000010; i++) {
		if (ans < co[i]) {
			ans = co[i];
		}
	}
	cout << ans << endl;
}
0