結果

問題 No.390 最長の数列
ユーザー imulanimulan
提出日時 2016-07-08 23:27:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,104 ms / 5,000 ms
コード長 1,213 bytes
コンパイル時間 2,056 ms
コンパイル使用メモリ 178,696 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-07-25 16:59:17
合計ジャッジ時間 6,315 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 505 ms
8,752 KB
testcase_06 AC 1,104 ms
8,640 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 470 ms
8,752 KB
testcase_11 AC 469 ms
8,648 KB
testcase_12 AC 469 ms
8,676 KB
testcase_13 AC 239 ms
7,380 KB
testcase_14 AC 346 ms
8,760 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 19 ms
4,380 KB
testcase_18 AC 30 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

typedef vector<int> vi;

//約数列挙
vi div_list(int x)
{
    vi v;
    for(int i=1; i*i<=x; ++i)
    {
        if(x%i==0)
        {
            v.pb(i);
            if(i!=x/i) v.pb(x/i);
        }
    }
    sort(all(v));
    return v;
}

int main()
{
    int n;
    cin >>n;

    vector<int> x(n);
    rep(i,n) scanf(" %d", &x[i]);
    sort(all(x));

    //それぞれの値のindexを保存
    map<int,int> idx;
    rep(i,n) idx[x[i]]=i;

    vi dp(n,1);

    rep(i,n)
    {
        //printf("now= %d\n", x[i]);
        vi d=div_list(x[i]);
        rep(j,d.size())
        {
            //約数
            int y=d[j];
            if(idx.find(y)!=idx.end() && y<x[i])
            {
                //printf("  y=%d\n", y);
                dp[i]=max(dp[i],dp[idx[y]]+1);
            }
        }
    }

    int ans=1;
    rep(i,n) ans=max(ans,dp[i]);
    cout << ans << endl;
    return 0;
}
0