結果

問題 No.390 最長の数列
ユーザー ShibuyapShibuyap
提出日時 2020-07-31 05:46:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 122 ms / 5,000 ms
コード長 961 bytes
コンパイル時間 2,679 ms
コンパイル使用メモリ 202,144 KB
実行使用メモリ 33,648 KB
最終ジャッジ日時 2023-09-19 04:46:55
合計ジャッジ時間 4,783 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
14,052 KB
testcase_01 AC 7 ms
14,104 KB
testcase_02 AC 8 ms
14,100 KB
testcase_03 AC 7 ms
13,748 KB
testcase_04 AC 8 ms
13,808 KB
testcase_05 AC 42 ms
14,132 KB
testcase_06 AC 122 ms
33,648 KB
testcase_07 AC 7 ms
13,868 KB
testcase_08 AC 6 ms
14,056 KB
testcase_09 AC 6 ms
13,748 KB
testcase_10 AC 52 ms
15,128 KB
testcase_11 AC 53 ms
15,084 KB
testcase_12 AC 52 ms
15,100 KB
testcase_13 AC 35 ms
14,308 KB
testcase_14 AC 86 ms
20,316 KB
testcase_15 AC 5 ms
13,884 KB
testcase_16 AC 6 ms
13,784 KB
testcase_17 AC 7 ms
13,824 KB
testcase_18 AC 9 ms
13,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 1000005
int f[MAX_N];

int d[MAX_N];
vector<int> G[200000];
int dfs(int x){
    if(d[x] != 0) return d[x];
    rep(i,G[x].size()){
        d[x] = max(d[x], dfs(G[x][i]));
    }
    d[x]++;
    return d[x];
}

int main() {
    int n;
    cin >> n;
    int x[n];
    rep(i,n) cin >> x[i];
    sort(x,x+n);
    
    rep(i,MAX_N) f[i] = -1;
    rep(i,n) f[x[i]] = i;
    rep(i,n){
        srep(j,2,10000000){
            if(x[i]*j >= MAX_N) break;
            if(f[x[i]*j] != -1){
                G[i].push_back(f[x[i]*j]);
            }
        }
    }
    int ans = 0;
    rep(i,n){
        ans = max(ans,dfs(i));
    }
    cout << ans << endl;
    return 0;
}
 
 
0