結果
問題 | No.390 最長の数列 |
ユーザー |
|
提出日時 | 2016-07-08 22:47:07 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 55 ms / 5,000 ms |
コード長 | 873 bytes |
コンパイル時間 | 429 ms |
コンパイル使用メモリ | 57,520 KB |
実行使用メモリ | 7,424 KB |
最終ジャッジ日時 | 2024-10-02 10:30:23 |
合計ジャッジ時間 | 1,246 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 15 |
ソースコード
#include <cstdio> #include <vector> #include <algorithm> #define repeat(i,n) for (int i = 0; (i) < (n); ++(i)) #define whole(f,x,...) ([&](decltype((x)) y) { return (f)(begin(y), end(y), ## __VA_ARGS__); })(x) using namespace std; template <class T> void setmax(T & a, T const & b) { if (a < b) a = b; } int main() { // input int n; scanf("%d", &n); vector<int> xs(n); repeat (i,n) scanf("%d", &xs[i]); // compute int l = *whole(max_element, xs); vector<bool> exists(l+1); for (int x : xs) exists[x] = true; vector<int> dp(l+1); whole(sort, xs); whole(reverse, xs); int ans = 0; for (int x : xs) { for (int y = x; y < l+1; y += x) { if (exists[y]) { setmax(dp[x], dp[y] + 1); } } setmax(ans, dp[x]); } // output printf("%d\n", ans); return 0; }