結果
問題 |
No.390 最長の数列
|
ユーザー |
![]() |
提出日時 | 2016-07-08 23:13:38 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 991 bytes |
コンパイル時間 | 1,514 ms |
コンパイル使用メモリ | 167,744 KB |
実行使用メモリ | 19,144 KB |
最終ジャッジ日時 | 2024-10-13 06:38:39 |
合計ジャッジ時間 | 7,061 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 5 WA * 10 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; #define int ll #define rep(i,n) for(int i = 0; i < (int)(n); ++i) #define all(c) begin(c), end(c) //#define fill(c,v) fill(decltype(v)*(begin(c)), decltype(v)*(end(c)), v) int n; int have[1000010]; int dp[1000010]; int rec(int k){ int &res = dp[k]; if(res != -1) return res; if(k == 1) return res = 1; res = 1; for(int i = 1; i*i <= k; ++i){ if(k%i == 0){ if(have[i]) res = max(res, rec(i)+1); if(i != 1 && have[k/i]) res = max(res, rec(k/i)+1); } } return res; } decltype(0) main(){ ios::sync_with_stdio(0); cin.tie(0); while(cin >> n){ memset(dp, -1, sizeof dp); memset(have, 0, sizeof have); int x; rep(i,n) cin >> x, have[x] = true; rep(i,1000010) if(have[i]) rec(i); // rep(i,20) cout << dp[i] << ' '; // cout << endl; cout << *max_element(dp,dp+100010) << endl; } }