結果

問題 No.390 最長の数列
ユーザー mayoko_mayoko_
提出日時 2016-07-08 22:48:02
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 385 ms / 5,000 ms
コード長 1,433 bytes
コンパイル時間 813 ms
コンパイル使用メモリ 101,876 KB
実行使用メモリ 8,436 KB
最終ジャッジ日時 2024-04-10 08:48:48
合計ジャッジ時間 3,480 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,812 KB
testcase_01 AC 3 ms
6,940 KB
testcase_02 AC 3 ms
6,940 KB
testcase_03 AC 3 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 385 ms
6,940 KB
testcase_06 AC 277 ms
8,352 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 3 ms
6,940 KB
testcase_09 AC 3 ms
6,940 KB
testcase_10 AC 283 ms
8,436 KB
testcase_11 AC 285 ms
8,408 KB
testcase_12 AC 283 ms
8,244 KB
testcase_13 AC 204 ms
8,352 KB
testcase_14 AC 113 ms
6,940 KB
testcase_15 AC 3 ms
6,940 KB
testcase_16 AC 3 ms
6,940 KB
testcase_17 AC 17 ms
8,296 KB
testcase_18 AC 25 ms
8,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>
#include<random>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

const int MAXN = 1001000;
bool exist[MAXN];
int dp[MAXN];

vi divs(int n) {
    vi ret;
    for (int i = 1; i*i <= n; i++) {
        if (n%i == 0) {
            ret.push_back(i);
            if (i*i < n) ret.push_back(n/i);
        }
    }
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) {
        int x;
        cin >> x;
        exist[x] = true;
    } 
    int ans = 1;
    for (int x = 1; x < MAXN; x++) {
        if (!exist[x]) continue;
        int& ret = dp[x];
        ret = 1;
        auto div = divs(x);
        for (int el : div) {
            if (el == x) continue;
            if (!exist[el]) continue;
            ret = max(ret, dp[el] + 1);
        }
        ans = max(ret, ans);
    }
    cout << ans << endl;
    return 0;
}
0