結果

問題 No.979 Longest Divisor Sequence
ユーザー totori_nyaatotori_nyaa
提出日時 2020-01-31 21:52:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 888 bytes
コンパイル時間 1,972 ms
コンパイル使用メモリ 179,052 KB
実行使用メモリ 13,576 KB
最終ジャッジ日時 2023-10-17 09:30:02
合計ジャッジ時間 4,678 ms
ジャッジサーバーID
(参考情報)
judge11 / 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 WA -
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 9 ms
4,348 KB
testcase_11 AC 9 ms
4,348 KB
testcase_12 AC 8 ms
4,348 KB
testcase_13 WA -
testcase_14 AC 1,554 ms
13,576 KB
testcase_15 AC 389 ms
7,880 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(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