結果

問題 No.390 最長の数列
ユーザー 0w10w1
提出日時 2016-11-21 01:45:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 37 ms / 5,000 ms
コード長 1,590 bytes
コンパイル時間 1,764 ms
コンパイル使用メモリ 170,012 KB
実行使用メモリ 7,680 KB
最終ジャッジ日時 2024-04-10 10:13:13
合計ジャッジ時間 2,730 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 23 ms
7,680 KB
testcase_06 AC 37 ms
7,516 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 4 ms
7,272 KB
testcase_09 AC 5 ms
7,104 KB
testcase_10 AC 27 ms
7,400 KB
testcase_11 AC 28 ms
7,472 KB
testcase_12 AC 27 ms
7,680 KB
testcase_13 AC 19 ms
7,468 KB
testcase_14 AC 20 ms
6,944 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 4 ms
7,196 KB
testcase_17 AC 4 ms
7,124 KB
testcase_18 AC 6 ms
7,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

typedef long long ll;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< vvi > vvvi;
typedef vector< vvvi > vvvvi;
typedef vector< vvvvi > vvvvvi;
typedef vector< ll > vl;
typedef vector< vl > vvl;
typedef vector< vvl > vvvl;
typedef vector< vvvl > vvvvl;
typedef vector< vvvvl > vvvvvl;
typedef pair< int, int > pii;
typedef vector< pii > vp;
typedef vector< vp > vvp;
typedef vector < string > vs;
typedef vector< vs > vvs;
typedef vector< double > vd;
typedef vector< vd > vvd;
typedef vector< vvd > vvvd;
typedef vector< bool > vb;
typedef vector< vb > vvb;

const int INF = 0x3f3f3f3f;
const int MOD7 = ( int ) 1e9 + 7;

template< class T1, class T2 >
int upmin( T1 &x, T2 v ){
    if( x > v ){
        x = v;
        return 1;
    }
    return 0;
}

template< class T1, class T2 >
int upmax( T1 &x, T2 v ){
    if( x < v ){
        x = v;
        return 1;
    }
    return 0;
}

int N;
vi A;

void init(){
    cin >> N;
    A = vi( N );
    for( int i = 0; i < N; ++i )
        cin >> A[ i ];
}

int maxa;
vi dp;

void preprocess(){
    sort( A.begin(), A.end() );
    maxa = *max_element( A.begin(), A.end() );
    dp = vi( maxa + 1, 1 );
    for( int i = 0; i < N; ++i )
        for( int j = A[ i ] + A[ i ]; j <= maxa; j += A[ i ] )
            upmax( dp[ j ], dp[ A[ i ] ] + 1 );
}

void solve(){
    int ans = 0;
    for( int i = 0; i < N; ++i )
        upmax( ans, dp[ A[ i ] ] );
    cout << ans << endl;
}

signed main(){
    ios::sync_with_stdio( 0 );
    init();
    preprocess();
    solve();
    return 0;
}
0