結果
問題 | No.390 最長の数列 |
ユーザー | kei |
提出日時 | 2018-11-30 23:59:10 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2,099 ms / 5,000 ms |
コード長 | 2,326 bytes |
コンパイル時間 | 1,820 ms |
コンパイル使用メモリ | 178,704 KB |
実行使用メモリ | 21,536 KB |
最終ジャッジ日時 | 2024-06-26 23:49:06 |
合計ジャッジ時間 | 7,804 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 30 ms
15,220 KB |
testcase_01 | AC | 23 ms
15,228 KB |
testcase_02 | AC | 29 ms
15,288 KB |
testcase_03 | AC | 24 ms
15,224 KB |
testcase_04 | AC | 27 ms
15,220 KB |
testcase_05 | AC | 76 ms
21,336 KB |
testcase_06 | AC | 2,099 ms
21,536 KB |
testcase_07 | AC | 20 ms
15,356 KB |
testcase_08 | AC | 17 ms
15,248 KB |
testcase_09 | AC | 21 ms
15,328 KB |
testcase_10 | AC | 384 ms
21,328 KB |
testcase_11 | AC | 406 ms
21,436 KB |
testcase_12 | AC | 351 ms
21,328 KB |
testcase_13 | AC | 547 ms
20,216 KB |
testcase_14 | AC | 638 ms
21,396 KB |
testcase_15 | AC | 17 ms
15,388 KB |
testcase_16 | AC | 18 ms
15,344 KB |
testcase_17 | AC | 22 ms
15,580 KB |
testcase_18 | AC | 26 ms
15,548 KB |
ソースコード
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int INF = 1e9; const ll LINF = 1e18; inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; } inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; } template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; } template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; } template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; } template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; } /* <url:https://yukicoder.me/problems/no/390> 問題文============================================================ ================================================================= 解説============================================================= ================================================================ */ const ll MAX_PRIME = 1000000; vector<int> primes; vector<int> is_prime(MAX_PRIME + 1,true); void init_primes(){ is_prime[0] = is_prime[1] = false; for(int i = 2; i <= MAX_PRIME;i++){ if(is_prime[i]){ primes.push_back(i); for(int j = i*2; j <= MAX_PRIME; j+=i) is_prime[j] = false; } } } ll solve(){ init_primes(); ll res = 0; ll N; cin >> N; vector<ll> dp(1000001); map<ll,bool> mp; for(int i = 0; i < N;i++){ ll x; cin >> x; mp[x] = true; dp[x] = 1; } for(int i = 1; i <= 1000000;i++){ if(dp[i] == 0) continue; res = max(res,dp[i]); for(int p = 2; ;p++){ if(p*i > 1000000) break; if(mp.count(p*i)){ dp[p*i] = max(dp[p*i],dp[i]+1); } } } return res; } int main(void) { cin.tie(0); ios_base::sync_with_stdio(false); cout << solve() << endl; return 0; }