結果
問題 | No.390 最長の数列 |
ユーザー | ngtkana |
提出日時 | 2020-04-05 18:45:08 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 531 ms / 5,000 ms |
コード長 | 1,316 bytes |
コンパイル時間 | 2,168 ms |
コンパイル使用メモリ | 208,080 KB |
実行使用メモリ | 20,268 KB |
最終ジャッジ日時 | 2023-09-16 06:48:34 |
合計ジャッジ時間 | 4,853 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,380 KB |
testcase_01 | AC | 2 ms
4,376 KB |
testcase_02 | AC | 2 ms
4,380 KB |
testcase_03 | AC | 2 ms
4,380 KB |
testcase_04 | AC | 2 ms
4,376 KB |
testcase_05 | AC | 61 ms
20,264 KB |
testcase_06 | AC | 531 ms
20,268 KB |
testcase_07 | AC | 2 ms
4,376 KB |
testcase_08 | AC | 44 ms
19,400 KB |
testcase_09 | AC | 74 ms
19,336 KB |
testcase_10 | AC | 224 ms
20,204 KB |
testcase_11 | AC | 227 ms
20,188 KB |
testcase_12 | AC | 237 ms
20,168 KB |
testcase_13 | AC | 64 ms
20,032 KB |
testcase_14 | AC | 49 ms
5,460 KB |
testcase_15 | AC | 3 ms
4,376 KB |
testcase_16 | AC | 61 ms
19,208 KB |
testcase_17 | AC | 83 ms
19,616 KB |
testcase_18 | AC | 105 ms
19,608 KB |
ソースコード
#include<bits/stdc++.h> #define ALL(v) std::begin(v),std::end(v) using lint=long long; using lubl=long double; void cmn(lint&x,lint y){if(x>y)x=y;} int main(){ std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false); std::cout.setf(std::ios_base::fixed);std::cout.precision(15); lint n;std::cin>>n; std::vector<lint>a(n); for(lint&x:a)std::cin>>x; std::sort(ALL(a)); lint m=*std::max_element(ALL(a))+1; std::vector<lint>primes; { std::vector<lint>sieve(m+1); for(lint p=2;p<=m;p++){ if(sieve.at(p))continue; primes.push_back(p); for(lint i=p*p;i<=m;i+=p)sieve.at(i)=true; } } std::vector<lint>dp(m),ep(m,-1); for(lint len=0;;len++){ dp.assign(m,n); for(lint i=n-1;i>=0;i--){ if(i<=ep.at(a.at(i)))continue; dp.at(a.at(i))=i; } if(std::all_of(ALL(dp),[n](lint x){return x==n;})){ std::cout<<len<<'\n'; return 0; } ep.assign(m,n); for(lint p:primes){ for(lint i=1;i<=(m-1)/p;i++){ cmn(ep.at(i*p),dp.at(i)); } } for(lint p:primes){ for(lint i=1;i<=(m-1)/p;i++){ cmn(ep.at(i*p),ep.at(i)); } } } }