結果

問題 No.979 Longest Divisor Sequence
ユーザー minatominato
提出日時 2020-02-01 16:19:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,255 bytes
コンパイル時間 2,014 ms
コンパイル使用メモリ 181,896 KB
実行使用メモリ 36,824 KB
最終ジャッジ日時 2023-10-19 00:06:32
合計ジャッジ時間 3,590 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,556 KB
testcase_01 AC 3 ms
4,556 KB
testcase_02 AC 3 ms
4,556 KB
testcase_03 AC 3 ms
4,556 KB
testcase_04 WA -
testcase_05 AC 3 ms
4,556 KB
testcase_06 AC 3 ms
4,556 KB
testcase_07 AC 3 ms
4,556 KB
testcase_08 AC 3 ms
4,556 KB
testcase_09 AC 3 ms
4,556 KB
testcase_10 AC 8 ms
4,820 KB
testcase_11 AC 9 ms
4,820 KB
testcase_12 AC 8 ms
4,820 KB
testcase_13 WA -
testcase_14 AC 569 ms
36,824 KB
testcase_15 AC 193 ms
15,116 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
//const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<int> A(N);
    rep(i,N) cin >> A[i];

    vector<vector<int>> G(N);
    rep(i,N) {
        G[i].emplace_back(1);
        for (int j = 2; j*j <= A[i]; j++) {
            if (A[i]%j==0) {
                G[i].emplace_back(j);
                G[i].emplace_back(A[i]/j);
            }
        }
    }

    vector<int> B(300001),dp(N);
    rep(i,N) {
        for (auto j : G[i]) {
            chmax(dp[i],B[j]+1);
        }
        chmax(B[A[i]],dp[i]);
    }

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