結果

問題 No.390 最長の数列
ユーザー Y17Y17
提出日時 2020-02-03 23:52:32
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,925 ms / 5,000 ms
コード長 661 bytes
コンパイル時間 3,282 ms
コンパイル使用メモリ 163,776 KB
実行使用メモリ 122,260 KB
最終ジャッジ日時 2023-10-19 15:50:04
合計ジャッジ時間 42,017 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,875 ms
119,920 KB
testcase_01 AC 1,882 ms
119,924 KB
testcase_02 AC 1,826 ms
119,924 KB
testcase_03 AC 1,824 ms
119,920 KB
testcase_04 AC 1,859 ms
119,920 KB
testcase_05 AC 1,888 ms
121,440 KB
testcase_06 AC 1,925 ms
122,260 KB
testcase_07 AC 1,843 ms
119,916 KB
testcase_08 AC 1,844 ms
120,004 KB
testcase_09 AC 1,837 ms
120,004 KB
testcase_10 AC 1,904 ms
122,260 KB
testcase_11 AC 1,913 ms
122,260 KB
testcase_12 AC 1,898 ms
122,260 KB
testcase_13 AC 1,851 ms
120,224 KB
testcase_14 AC 1,904 ms
120,500 KB
testcase_15 AC 1,889 ms
119,932 KB
testcase_16 AC 1,883 ms
120,372 KB
testcase_17 AC 1,860 ms
121,876 KB
testcase_18 AC 1,836 ms
121,900 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

vector<int> vec[1000010];
int memo[1000010] = {};
int ans[100000] = {};
int main(){
    int n;
    int a[100010];
    cin >> n;
    for(int i = 0;i < n;i++) cin >> a[i];
    sort(a, a+n);

    for(int i = 1;i <= 1000000;i++){
        for(int j = i+i;j <= 1000000;j+=i){
            vec[j].push_back(i);
        }
    }



    int aans = 0;
    for(int i = n-1;i >= 0;i--){
        ans[i] = memo[a[i]] + 1;
        aans = max(aans, ans[i]);
        for(int j = 0;j < vec[a[i]].size();j++){
            memo[vec[a[i]][j]] = max(memo[vec[a[i]][j]], ans[i]);
        }
    }

    cout << aans << endl;

    return 0;
}
0