結果

問題 No.979 Longest Divisor Sequence
ユーザー totori_nyaatotori_nyaa
提出日時 2020-01-31 21:53:12
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,476 ms / 2,000 ms
コード長 901 bytes
コンパイル時間 1,823 ms
コンパイル使用メモリ 178,864 KB
実行使用メモリ 13,640 KB
最終ジャッジ日時 2023-10-17 09:30:51
合計ジャッジ時間 4,505 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 8 ms
4,348 KB
testcase_11 AC 8 ms
4,348 KB
testcase_12 AC 8 ms
4,348 KB
testcase_13 AC 21 ms
4,764 KB
testcase_14 AC 1,476 ms
13,640 KB
testcase_15 AC 370 ms
7,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    map<int,int> mp;
    int ans = 1;
    for(int i=0;i<n;i++){
        if(a[i] != 1 && mp.count(1)){
            mp[a[i]] = max(mp[a[i]],mp[1]+1);
        }
        for(int j=2;j*j<=a[i];j++){
            if(a[i]%j==0){
                if(mp.count(j)){
                    mp[a[i]] = max(mp[a[i]],mp[j]+1);
                }
                if(j*j != a[i] && mp.count(a[i]/j)){
                    mp[a[i]] = max(mp[a[i]],mp[a[i]/j]+1);
                }
            }
        }
        mp[a[i]] = max(1,mp[a[i]]);
        //cerr << a[i] << " " << mp[a[i]] << endl;
    }
    for(auto i:mp){
        ans = max(ans,i.second);
    }
    cout << ans << endl;
}
0