結果

問題 No.979 Longest Divisor Sequence
ユーザー nejinejinejineji
提出日時 2020-01-31 22:20:41
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,289 ms / 2,000 ms
コード長 1,195 bytes
コンパイル時間 1,813 ms
コンパイル使用メモリ 169,432 KB
実行使用メモリ 8,060 KB
最終ジャッジ日時 2023-10-17 10:17:45
合計ジャッジ時間 4,343 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,684 KB
testcase_01 AC 3 ms
5,684 KB
testcase_02 AC 4 ms
5,684 KB
testcase_03 AC 3 ms
5,684 KB
testcase_04 AC 3 ms
5,684 KB
testcase_05 AC 3 ms
5,684 KB
testcase_06 AC 4 ms
5,684 KB
testcase_07 AC 3 ms
5,684 KB
testcase_08 AC 3 ms
5,684 KB
testcase_09 AC 3 ms
5,684 KB
testcase_10 AC 16 ms
5,684 KB
testcase_11 AC 16 ms
5,684 KB
testcase_12 AC 17 ms
5,684 KB
testcase_13 AC 49 ms
8,060 KB
testcase_14 AC 1,289 ms
8,060 KB
testcase_15 AC 432 ms
6,476 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i, x, y) for (ll i = x; i <= y; i++)
#define BIT(t) (1ll << t)
#define PER(i, y, x) for (ll i = y; i >= x; i--)
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define pll pair<ll, ll>
#define SIZE(v) ll(v.size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
//        ios::sync_with_stdio(false);
//        cin.tie(nullptr);

int main(){
        ll n;
        cin >> n;
        vll a(n+1);
        ll const MAX = 3e5 + 1;
        vll v(MAX, 0);
        REP(i,1,n){
                cin >> a[i];
        }
        REP(i,1,n){
                ll t = a[i];
                if(t == 1){
                        v[1] = 1;
                        continue;
                }
                v[t] = max(v[t], v[1] + 1);
                for(ll i = 2;i * i<=t;i++){
                        if(t % i == 0){
                                ll j = t / i;
                                v[t] = max({v[t], v[i] + 1, v[j] + 1});
                        }
                }
        }
        ll ans = 0;
        REP(i,1,MAX){
                ans = max(ans, v[i]);
        }
        cout << ans << endl;

}
0