結果
問題 | No.390 最長の数列 |
ユーザー |
|
提出日時 | 2019-10-15 15:45:04 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,546 ms / 5,000 ms |
コード長 | 986 bytes |
コンパイル時間 | 2,118 ms |
コンパイル使用メモリ | 176,728 KB |
実行使用メモリ | 12,272 KB |
最終ジャッジ日時 | 2024-12-29 15:24:30 |
合計ジャッジ時間 | 6,759 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 15 |
ソースコード
#include<bits/stdc++.h> #define EM 1000000 using namespace std; using LL = long long; using P = pair<LL, LL>; LL LINF = 1e18; int INF = 1e9; LL mod = 1e9+7; using vint = vector<int>; using vLL = vector<LL>; using vvint = vector<vector<int>>; using vvLL = vector<vector<LL>>; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } int main(){ int N; cin >> N; vector<int> x(N), cnt(1e6+1, 1); set<int> xx; for(int i = 0;i < N;i++){ cin >> x[i]; xx.insert(x[i]); } sort(x.begin(), x.end()); for(int i = 0;i < N;i++){ for(int j = 2;j*x[i] <= 1e6;j++){ auto itr = xx.find(j*x[i]); if(itr != xx.end()){ cnt[*itr] = max(cnt[*itr], cnt[x[i]]+1); } } } int ans = 0; for(auto c : cnt) ans = max(ans, c); cout << ans << endl; }