結果

問題 No.390 最長の数列
ユーザー HachimoriHachimori
提出日時 2016-07-08 23:18:28
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 633 ms / 5,000 ms
コード長 903 bytes
コンパイル時間 507 ms
コンパイル使用メモリ 61,760 KB
実行使用メモリ 7,808 KB
最終ジャッジ日時 2023-07-25 16:59:02
合計ジャッジ時間 4,437 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
7,308 KB
testcase_01 AC 5 ms
7,204 KB
testcase_02 AC 4 ms
7,288 KB
testcase_03 AC 5 ms
7,196 KB
testcase_04 AC 4 ms
7,524 KB
testcase_05 AC 633 ms
7,692 KB
testcase_06 AC 402 ms
7,808 KB
testcase_07 AC 4 ms
7,256 KB
testcase_08 AC 5 ms
7,344 KB
testcase_09 AC 5 ms
7,288 KB
testcase_10 AC 450 ms
7,616 KB
testcase_11 AC 452 ms
7,668 KB
testcase_12 AC 451 ms
7,808 KB
testcase_13 AC 328 ms
7,508 KB
testcase_14 AC 172 ms
7,644 KB
testcase_15 AC 5 ms
7,296 KB
testcase_16 AC 5 ms
7,476 KB
testcase_17 AC 25 ms
7,304 KB
testcase_18 AC 38 ms
7,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int NUM_VAL = 100005;
const int VAL_RANGE = 1000005;


int nVal;
int val[NUM_VAL];

void read() {
    cin >> nVal;
    for (int i = 0; i < nVal; ++i) {
        cin >> val[i];
    }
}


void work() {
    sort(val, val + nVal);
    
    static int dp[VAL_RANGE];
    memset(dp, 0, sizeof(dp));

    for (int i = 0; i < nVal; ++i) {
        int toAdd = 1;
        for (int divisor = 1; divisor * divisor <= val[i]; ++divisor) {
            if (val[i] % divisor == 0) {
                toAdd = max(toAdd, dp[divisor] + 1);
            }
            if (val[i] % (val[i] / divisor) == 0) {
                toAdd = max(toAdd, dp[(val[i] / divisor)] + 1);
            }
        }
        dp[val[i]] = toAdd;
    }

    cout << *max_element(dp, dp + VAL_RANGE) << endl;
}


int main() {
    read();
    work();
    return 0;
}
0