結果

問題 No.390 最長の数列
ユーザー BantakoBantako
提出日時 2018-07-09 10:30:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 53 ms / 5,000 ms
コード長 643 bytes
コンパイル時間 1,761 ms
コンパイル使用メモリ 166,496 KB
実行使用メモリ 7,476 KB
最終ジャッジ日時 2023-09-22 08:33:14
合計ジャッジ時間 2,919 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
6,912 KB
testcase_01 AC 6 ms
6,868 KB
testcase_02 AC 6 ms
7,044 KB
testcase_03 AC 5 ms
6,996 KB
testcase_04 AC 6 ms
6,872 KB
testcase_05 AC 33 ms
7,136 KB
testcase_06 AC 51 ms
7,128 KB
testcase_07 AC 6 ms
6,872 KB
testcase_08 AC 5 ms
7,040 KB
testcase_09 AC 5 ms
7,040 KB
testcase_10 AC 40 ms
7,476 KB
testcase_11 AC 40 ms
7,136 KB
testcase_12 AC 38 ms
7,212 KB
testcase_13 AC 33 ms
7,300 KB
testcase_14 AC 53 ms
7,280 KB
testcase_15 AC 4 ms
6,936 KB
testcase_16 AC 4 ms
6,912 KB
testcase_17 AC 6 ms
7,032 KB
testcase_18 AC 7 ms
6,868 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:7:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
    7 | main(){
      | ^~~~

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    const int MAX_V = 1000000;
    int N;
    cin >> N;
    vector<int> V(N),cnt(MAX_V+1);
    rep(i,0,N){
        cin >> V[i];
        cnt[V[i]] = 1;
    }
    for(int i = MAX_V;i >= 1;i--){
        if(!cnt[i])continue;
        int maxi = 0;
        for(int j = i * 2;j <= MAX_V;j += i){
            maxi = max(maxi, cnt[j]);
        }
        cnt[i] = max(cnt[i], maxi + 1);
    }
    int maxi = 0;
    rep(i,1,MAX_V+1)maxi = max(maxi, cnt[i]);
    cout << maxi << endl;
}
0