結果

問題 No.390 最長の数列
ユーザー ctyl_0ctyl_0
提出日時 2016-07-08 23:30:32
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 361 ms / 5,000 ms
コード長 1,821 bytes
コンパイル時間 1,322 ms
コンパイル使用メモリ 91,704 KB
実行使用メモリ 11,364 KB
最終ジャッジ日時 2023-07-25 16:59:21
合計ジャッジ時間 3,845 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
10,960 KB
testcase_01 AC 6 ms
10,820 KB
testcase_02 AC 7 ms
10,760 KB
testcase_03 AC 6 ms
10,940 KB
testcase_04 AC 7 ms
10,904 KB
testcase_05 AC 361 ms
11,364 KB
testcase_06 AC 287 ms
11,328 KB
testcase_07 AC 6 ms
10,804 KB
testcase_08 AC 7 ms
10,832 KB
testcase_09 AC 6 ms
10,788 KB
testcase_10 AC 272 ms
11,348 KB
testcase_11 AC 274 ms
11,352 KB
testcase_12 AC 275 ms
11,204 KB
testcase_13 AC 171 ms
11,028 KB
testcase_14 AC 118 ms
11,164 KB
testcase_15 AC 6 ms
10,880 KB
testcase_16 AC 7 ms
10,816 KB
testcase_17 AC 18 ms
10,780 KB
testcase_18 AC 26 ms
10,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define repd(i,a,b) for (int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template
vector<int> dec(int y){
    vector<int> ret;
    ret.pb(1);
    for(int i = 2; i * i <= y; i++){
        if(y % i == 0){
            ret.pb(i);
            if(i != y / i) ret.pb(y / i);
        }
    }
    sort(all(ret));
    reverse(all(ret));
    return ret;
}

template <typename T> inline void voutput(T &v){
    rep(i, v.size()){
        if (i) cout << " " << v[i];
        else cout << v[i];
    }
    cout << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    
    int N;
    cin >> N;
    vector<int> X(1000001, 0);
    vector<int> Y(N);
    vector<int> ret(1000001, 1);
    rep(i, N){
        int x;
        cin >> x;
        X[x] = 1;
        Y[i] = x;
    }
    
    sort(all(Y));
    
    int ans = 1;
    
    rep(i, N){
        vector<int> D = dec(Y[i]);
//        cout << Y[i] << ": ";
//        voutput(D);
        for(int d: D){
            if(Y[i] == 1) break;
            if(X[d] == 1){
                ret[Y[i]] = max(ret[Y[i]], ret[d] + 1);
            }
        }
//        cout << Y[i] << ", " << ret[Y[i]] << endl;
        ans = max(ans, ret[Y[i]]);
    }
    
    output(ans, 0);
    
    
    return 0;
}
0