結果

問題 No.979 Longest Divisor Sequence
ユーザー kyort0nkyort0n
提出日時 2020-01-31 21:45:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,297 bytes
コンパイル時間 1,605 ms
コンパイル使用メモリ 169,948 KB
実行使用メモリ 8,432 KB
最終ジャッジ日時 2023-10-17 09:07:25
合計ジャッジ時間 3,122 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 4 ms
8,424 KB
testcase_04 AC 3 ms
8,424 KB
testcase_05 WA -
testcase_06 AC 4 ms
8,424 KB
testcase_07 WA -
testcase_08 AC 3 ms
8,424 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 29 ms
8,368 KB
testcase_14 WA -
testcase_15 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:48:41: warning: iteration 299999 invokes undefined behavior [-Waggressive-loop-optimizations]
   48 |     for(int i = 1; i <= 3e5; i++) dp[i] = 1;
      |                                   ~~~~~~^~~
main.cpp:48:22: note: within this loop
   48 |     for(int i = 1; i <= 3e5; i++) dp[i] = 1;
      |                    ~~^~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
ll N;
ll A[300000];
ll dp[300000];

vector<int> Div(int a) {
    vector<int> ret;
    for(int i = 1; i * i <= a; i++) {
        if(a % i != 0) continue;
        ret.push_back(i);
        if(i * i != a) ret.push_back(a / i);
    }
    return ret;
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    for(int i = 0; i < N; i++) cin >> A[i];
    for(int i = 1; i <= 3e5; i++) dp[i] = 1;
    ll ans = 0;
    for(int i = N - 1; i >= 0; i--) {
        //for(int i = 0; i <= 10; i++) cerr << dp[i] << " ";
        //cerr << endl;
        ll New = dp[A[i]] + 1;
        chmax(ans, dp[A[i]]);
        vector<int> v = Div(A[i]);
        for(auto val : v) {
            if(val == A[i]) continue;
            chmax(dp[val], New);
        }
    }
    cout << ans << endl;
    return 0;
}
0