結果
問題 |
No.390 最長の数列
|
ユーザー |
|
提出日時 | 2016-10-08 00:46:47 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 71 ms / 5,000 ms |
コード長 | 990 bytes |
コンパイル時間 | 1,011 ms |
コンパイル使用メモリ | 105,868 KB |
実行使用メモリ | 7,364 KB |
最終ジャッジ日時 | 2024-10-02 11:58:56 |
合計ジャッジ時間 | 2,162 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 15 |
ソースコード
#define _USE_MATH_DEFINES #include <cstdio> #include <iostream> #include <sstream> #include <fstream> #include <iomanip> #include <algorithm> #include <cmath> #include <complex> #include <string> #include <vector> #include <list> #include <queue> #include <stack> #include <set> #include <map> #include <bitset> #include <numeric> #include <limits> #include <climits> #include <cfloat> #include <functional> #include <iterator> using namespace std; const int MAX = 1000000; int main() { int n; cin >> n; vector<bool> check(MAX + 1, false); for(int i=0; i<n; ++i){ int x; cin >> x; check[x] = true; } vector<int> dp(MAX + 1, 0); for(int i=1; i<=MAX; ++i){ if(!check[i]) continue; dp[i] = max(dp[i], 1); for(int j=2; i*j<=MAX; ++j){ if(check[i*j]) dp[i*j] = max(dp[i*j], dp[i] + 1); } } cout << *max_element(dp.begin(), dp.end()) << endl; return 0; }