結果

問題 No.390 最長の数列
ユーザー algon_320algon_320
提出日時 2016-10-29 19:02:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 424 ms / 5,000 ms
コード長 1,496 bytes
コンパイル時間 1,697 ms
コンパイル使用メモリ 168,272 KB
実行使用メモリ 11,492 KB
最終ジャッジ日時 2024-04-10 10:13:02
合計ジャッジ時間 4,760 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
11,368 KB
testcase_01 AC 5 ms
11,352 KB
testcase_02 AC 5 ms
11,468 KB
testcase_03 AC 4 ms
11,396 KB
testcase_04 AC 5 ms
11,428 KB
testcase_05 AC 424 ms
11,472 KB
testcase_06 AC 301 ms
11,492 KB
testcase_07 AC 5 ms
11,424 KB
testcase_08 AC 5 ms
11,380 KB
testcase_09 AC 6 ms
11,424 KB
testcase_10 AC 311 ms
11,380 KB
testcase_11 AC 319 ms
11,444 KB
testcase_12 AC 306 ms
11,384 KB
testcase_13 AC 222 ms
11,348 KB
testcase_14 AC 133 ms
11,364 KB
testcase_15 AC 5 ms
11,416 KB
testcase_16 AC 5 ms
11,400 KB
testcase_17 AC 20 ms
11,428 KB
testcase_18 AC 27 ms
11,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
// #define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
#define ITR(v,c) for(auto v=begin(c);v!=end(c);v++)
#define FORE(x,c) for(auto &x:c)
#define FOR(v,a,n) for(int v=a;v<(int)(n);v++)
#define REP(v,n) FOR(v,0,n)
#define RREP(v,n) for(int v=((int)(n)-1);v>=0;v--)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define SZ(c) ((int)c.size())
const int DX[9]={0,1,0,-1,1,1,-1,-1,0}, DY[9]={-1,0,1,0,-1,1,1,-1,0};
const int INF=1e9; const long long INFLL=1e18;
template<class T> ostream& operator << (ostream &os, const vector<T> &v) {
    ITR(i,v) os<<*i<<(i==end(v)-1?"":" "); return os; }
template<class T> istream& operator >> (istream &is, vector<T> &v) {
    ITR(i,v) is>>*i; return is; }
//------------------------------------------------------------------------------

ll dp[1000001];
signed main() {
    int n;
    cin>>n;
    vi a(n);
    cin>>a;
    fill(ALL(dp),-INF);
    FORE(x,a) dp[x]=1;

    int M=(*max_element(ALL(a)));
    ll ans=0;
    FOR(i,1,M+1) {
        if(dp[i]<0) continue;
        vi div;
        for(int j=1; j*j<=i; j++) {
            if(i%j==0) {
                div.push_back(j);
                div.push_back(i/j);
            }
        }
        FORE(x,div) {
            if(x==i) continue;
            dp[i]=max(dp[i],dp[x]+1);
        }
        ans=max(ans,dp[i]);
    }
    cout<<ans<<endl;
    return 0;
}
0