結果

問題 No.390 最長の数列
ユーザー Im_GimletIm_Gimlet
提出日時 2020-09-05 13:28:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 62 ms / 5,000 ms
コード長 899 bytes
コンパイル時間 1,550 ms
コンパイル使用メモリ 168,412 KB
実行使用メモリ 7,692 KB
最終ジャッジ日時 2023-08-18 20:58:03
合計ジャッジ時間 3,037 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
6,932 KB
testcase_01 AC 5 ms
6,964 KB
testcase_02 AC 5 ms
7,028 KB
testcase_03 AC 5 ms
6,932 KB
testcase_04 AC 5 ms
7,044 KB
testcase_05 AC 37 ms
7,260 KB
testcase_06 AC 50 ms
7,140 KB
testcase_07 AC 4 ms
6,996 KB
testcase_08 AC 3 ms
6,880 KB
testcase_09 AC 4 ms
6,908 KB
testcase_10 AC 40 ms
7,244 KB
testcase_11 AC 41 ms
7,128 KB
testcase_12 AC 40 ms
7,580 KB
testcase_13 AC 31 ms
7,140 KB
testcase_14 AC 62 ms
7,692 KB
testcase_15 AC 3 ms
7,048 KB
testcase_16 AC 3 ms
6,988 KB
testcase_17 AC 5 ms
6,872 KB
testcase_18 AC 6 ms
7,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<ll, ll>;
const long double PI = acos(-1.0L);
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

int n;

int main() {
    cin >> n;
    vector<int> xvec(n, 0);
    for(int i = 0; i < n ; ++i) cin >> xvec[i];

    sort(xvec.begin(), xvec.end());
    vector<int> dp(1000100, 0);
    
    for(int i = 0; i < n; ++i) {
        int ch = xvec[i];
        int now = dp[ch]+1;
        while(ch <= 1000000) {
            chmax(dp[ch], now);
            ch += xvec[i];
        }
    }

    int ans = 0;
    for(int i = 0; i < n; ++i) chmax(ans, dp[xvec[i]]);
    cout << ans << endl;
}
0