結果

問題 No.979 Longest Divisor Sequence
ユーザー unolightunolight
提出日時 2021-07-08 11:40:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 412 ms / 2,000 ms
コード長 674 bytes
コンパイル時間 546 ms
コンパイル使用メモリ 71,128 KB
実行使用メモリ 5,320 KB
最終ジャッジ日時 2023-09-14 04:45:58
合計ジャッジ時間 1,941 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 7 ms
4,720 KB
testcase_11 AC 7 ms
4,624 KB
testcase_12 AC 7 ms
4,532 KB
testcase_13 AC 17 ms
4,380 KB
testcase_14 AC 412 ms
5,320 KB
testcase_15 AC 142 ms
4,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

const int MAX=300010;
int d[MAX];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vector<int> a(n);
    for ( int i=0; i<n; i++ ) cin>>a[i];
    for ( int i=0; i<n; i++ ) {
        int res=1;
        for ( int j=1; j*j<=a[i]; j++ ) {
            if ( j<a[i] && a[i]%j==0 ) {
                res=max(res,d[j]+1);
                if ( a[i]/j<a[i] && a[i]/j!=j ) res=max(res,d[a[i]/j]+1);
            }
        }
        d[a[i]]=max(d[a[i]],res);
    }
    int ans=0;
    for ( int i=1; i<MAX; i++ ) ans=max(ans,d[i]);
    cout<<ans<<'\n';
    return 0;
}
0