結果

問題 No.390 最長の数列
ユーザー treeonetreeone
提出日時 2016-07-14 08:29:46
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,128 ms / 5,000 ms
コード長 792 bytes
コンパイル時間 1,431 ms
コンパイル使用メモリ 166,156 KB
実行使用メモリ 11,820 KB
最終ジャッジ日時 2024-04-10 09:09:57
合計ジャッジ時間 7,545 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
10,892 KB
testcase_01 AC 5 ms
10,952 KB
testcase_02 AC 6 ms
10,908 KB
testcase_03 AC 5 ms
10,996 KB
testcase_04 AC 4 ms
10,952 KB
testcase_05 AC 1,128 ms
11,648 KB
testcase_06 AC 726 ms
11,644 KB
testcase_07 AC 5 ms
10,976 KB
testcase_08 AC 5 ms
11,024 KB
testcase_09 AC 5 ms
10,884 KB
testcase_10 AC 803 ms
11,820 KB
testcase_11 AC 800 ms
11,644 KB
testcase_12 AC 801 ms
11,648 KB
testcase_13 AC 579 ms
11,548 KB
testcase_14 AC 299 ms
11,688 KB
testcase_15 AC 6 ms
11,024 KB
testcase_16 AC 6 ms
10,884 KB
testcase_17 AC 42 ms
11,024 KB
testcase_18 AC 64 ms
11,108 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repp(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
typedef pair<int, int> P;

vector<int> divisor(int n){
	vector<int> res;
	for(int i=1;i*i<=n;i++){
		if(n%i==0){
			res.push_back(i);
			if(i!=n/i) res.push_back(n/i);
		}
	}
	return res;
}

signed main(){
    int n;
    cin >> n;
    vector<int> x(n);
    rep(i, 0, n) cin >> x[i];
    sort(all(x));
    vector<int> dp(1000001);

    for(auto i: x){
        dp[i] = 1;
        auto v = divisor(i);
        for(auto j: v){
            if(j == i) continue;
            dp[i] = max(dp[i], dp[j] + 1);
        }
    }

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