結果

問題 No.390 最長の数列
ユーザー 🍡yurahuna🍡yurahuna
提出日時 2016-07-08 23:49:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,113 ms / 5,000 ms
コード長 1,314 bytes
コンパイル時間 1,739 ms
コンパイル使用メモリ 172,176 KB
実行使用メモリ 11,840 KB
最終ジャッジ日時 2024-04-10 08:52:58
合計ジャッジ時間 7,776 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
10,900 KB
testcase_01 AC 6 ms
11,008 KB
testcase_02 AC 6 ms
11,104 KB
testcase_03 AC 6 ms
10,984 KB
testcase_04 AC 7 ms
11,104 KB
testcase_05 AC 1,113 ms
11,804 KB
testcase_06 AC 692 ms
11,772 KB
testcase_07 AC 6 ms
11,120 KB
testcase_08 AC 6 ms
11,072 KB
testcase_09 AC 6 ms
11,032 KB
testcase_10 AC 779 ms
11,840 KB
testcase_11 AC 779 ms
11,776 KB
testcase_12 AC 780 ms
11,788 KB
testcase_13 AC 566 ms
11,704 KB
testcase_14 AC 278 ms
11,840 KB
testcase_15 AC 6 ms
11,112 KB
testcase_16 AC 6 ms
10,964 KB
testcase_17 AC 41 ms
11,152 KB
testcase_18 AC 64 ms
11,108 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
typedef vector<vector<int>> Graph;
const int inf = 1e9;
const int mod = 1e9 + 7;

// 自身以外の約数を列挙(12 -> {1, 2, 3, 6}, 8 -> {1, 2, 4})
vector<int> divisor(int n) {
	if (n == 1) return {};
    vector<int> res;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            res.emplace_back(i);
            if (i != 1 && i != n / i) res.emplace_back(n / i);
        }
    }
    return res;
}


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

	int N;
	cin >> N;
	V a(N);
	rep(i, N) cin >> a[i];
	sort(all(a));

	const int MAX = 1e6 + 1;
	V dp(MAX);
	for (auto x : a) {
		dp[x] = 1;
		auto v = divisor(x);
		for (auto y : v) {
			dp[x] = max(dp[x], dp[y] + 1);
		}
		// rep(z, 10) {
		// 	cout << dp[z] << " ";
		// }
		// cout << endl;
	}

	cout << *max_element(all(dp)) << endl;

}
0