結果

問題 No.390 最長の数列
ユーザー fmhrfmhr
提出日時 2016-07-09 00:00:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 919 bytes
コンパイル時間 1,622 ms
コンパイル使用メモリ 165,756 KB
実行使用メモリ 9,216 KB
最終ジャッジ日時 2024-04-21 08:47:47
合計ジャッジ時間 8,288 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define INF INT_MAX/3
#define MAX 1000000

using namespace std;

int n;
int A[MAX + 1];
int L[MAX];

int lis() {
    L[0] = A[0];
    int length = 1;
    for (int i = 1; i < n; ++i) {
        if (L[length - 1] < A[i] && A[i] % L[length - 1] == 0) {
            L[length++] = A[i];
        } else {
            *lower_bound(L, L + length, A[i]) = A[i];
        }
    }
    return int(lower_bound(L, L+length, INF) - L);
}

int dp[MAX];
int lis2(){
    int res = 0;
    for (int i = 0; i < n; ++i) {
        dp[i] = 1;
        for (int j = 0; j < i; ++j) {
            if (A[j]<A[i] && A[i]%A[j]==0){
                dp[i] = max(dp[i], dp[j] + 1);
            }
        }
        res = max(res, dp[i]);
    }
    return res;
}


int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
    }
    sort(begin(A), begin(A) + n);
    cout << lis2() << endl;
    return 0;
};
0