結果

問題 No.390 最長の数列
ユーザー kimiyukikimiyuki
提出日時 2016-07-08 22:47:07
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 61 ms / 5,000 ms
コード長 873 bytes
コンパイル時間 556 ms
コンパイル使用メモリ 58,712 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2024-04-10 08:47:49
合計ジャッジ時間 1,467 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,812 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 21 ms
7,752 KB
testcase_06 AC 61 ms
7,804 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 4 ms
7,416 KB
testcase_09 AC 5 ms
7,340 KB
testcase_10 AC 26 ms
7,800 KB
testcase_11 AC 28 ms
7,804 KB
testcase_12 AC 28 ms
7,808 KB
testcase_13 AC 20 ms
7,848 KB
testcase_14 AC 24 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 4 ms
7,388 KB
testcase_17 AC 4 ms
7,468 KB
testcase_18 AC 5 ms
7,428 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <vector>
#include <algorithm>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
#define whole(f,x,...) ([&](decltype((x)) y) { return (f)(begin(y), end(y), ## __VA_ARGS__); })(x)
using namespace std;
template <class T> void setmax(T & a, T const & b) { if (a < b) a = b; }
int main() {
    // input
    int n; scanf("%d", &n);
    vector<int> xs(n); repeat (i,n) scanf("%d", &xs[i]);
    // compute
    int l = *whole(max_element, xs);
    vector<bool> exists(l+1);
    for (int x : xs) exists[x] = true;
    vector<int> dp(l+1);
    whole(sort, xs);
    whole(reverse, xs);
    int ans = 0;
    for (int x : xs) {
        for (int y = x; y < l+1; y += x) {
            if (exists[y]) {
                setmax(dp[x], dp[y] + 1);
            }
        }
        setmax(ans, dp[x]);
    }
    // output
    printf("%d\n", ans);
    return 0;
}
0