結果

問題 No.390 最長の数列
ユーザー koyoprokoyopro
提出日時 2019-12-30 12:28:24
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,072 ms / 5,000 ms
コード長 1,294 bytes
コンパイル時間 1,227 ms
コンパイル使用メモリ 162,048 KB
実行使用メモリ 12,796 KB
最終ジャッジ日時 2024-04-25 14:49:18
合計ジャッジ時間 7,157 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
11,896 KB
testcase_01 AC 5 ms
12,048 KB
testcase_02 AC 5 ms
12,084 KB
testcase_03 AC 4 ms
12,048 KB
testcase_04 AC 4 ms
12,072 KB
testcase_05 AC 1,072 ms
12,688 KB
testcase_06 AC 665 ms
12,716 KB
testcase_07 AC 5 ms
11,980 KB
testcase_08 AC 5 ms
12,028 KB
testcase_09 AC 5 ms
11,880 KB
testcase_10 AC 758 ms
12,700 KB
testcase_11 AC 774 ms
12,796 KB
testcase_12 AC 755 ms
12,680 KB
testcase_13 AC 547 ms
12,508 KB
testcase_14 AC 270 ms
12,784 KB
testcase_15 AC 3 ms
12,084 KB
testcase_16 AC 4 ms
12,056 KB
testcase_17 AC 38 ms
12,016 KB
testcase_18 AC 59 ms
12,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define array2(type, x, y) array<array<type, y>, x>
#define vector2(type) vector<vector<type> >
#define out(...) printf(__VA_ARGS__)
#define MAX LONG_LONG_MAX

int dxy[] = {0, 1, 0, -1, 0};

/*================================*/

int N;
int DP[1100000];

signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin >> N;
    
    int X[N];
    REP(i, N) cin >> X[i];
    sort(X, X+N);
    
    REP(i, 1100000) DP[i] = 0;
    REP(i, N) DP[X[i]] = 1;
    
    int ans = 0;
    REP(i, N) {
        int x = X[i];
        FOR(j, 1, sqrt(x)+1) {
            if (x % j != 0) continue;
            int k = x / j;
            if (j != x) DP[x] = max(DP[x], DP[j] + 1);
            if (k != x && j != k) DP[x] = max(DP[x], DP[k] + 1);
            ans = max(ans, DP[x]);
        }
    }
    
    cout << ans << endl;
    
    
    return 0;
}
0