結果

問題 No.390 最長の数列
ユーザー mamekinmamekin
提出日時 2016-10-08 00:46:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 71 ms / 5,000 ms
コード長 990 bytes
コンパイル時間 959 ms
コンパイル使用メモリ 105,924 KB
実行使用メモリ 7,428 KB
最終ジャッジ日時 2024-04-10 10:09:19
合計ジャッジ時間 2,177 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
7,360 KB
testcase_01 AC 7 ms
7,316 KB
testcase_02 AC 8 ms
7,208 KB
testcase_03 AC 7 ms
7,360 KB
testcase_04 AC 8 ms
7,288 KB
testcase_05 AC 39 ms
7,296 KB
testcase_06 AC 71 ms
7,428 KB
testcase_07 AC 7 ms
7,292 KB
testcase_08 AC 6 ms
7,424 KB
testcase_09 AC 7 ms
7,264 KB
testcase_10 AC 43 ms
7,272 KB
testcase_11 AC 43 ms
7,200 KB
testcase_12 AC 43 ms
7,232 KB
testcase_13 AC 35 ms
7,216 KB
testcase_14 AC 50 ms
7,208 KB
testcase_15 AC 6 ms
7,368 KB
testcase_16 AC 6 ms
7,200 KB
testcase_17 AC 8 ms
7,268 KB
testcase_18 AC 9 ms
7,404 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

const int MAX = 1000000;

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

    vector<bool> check(MAX + 1, false);
    for(int i=0; i<n; ++i){
        int x;
        cin >> x;
        check[x] = true;
    }

    vector<int> dp(MAX + 1, 0);
    for(int i=1; i<=MAX; ++i){
        if(!check[i])
            continue;

        dp[i] = max(dp[i], 1);
        for(int j=2; i*j<=MAX; ++j){
            if(check[i*j])
                dp[i*j] = max(dp[i*j], dp[i] + 1);
        }
    }
    cout << *max_element(dp.begin(), dp.end()) << endl;

    return 0;
}
0