結果
問題 |
No.390 最長の数列
|
ユーザー |
![]() |
提出日時 | 2025-04-20 22:50:19 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 61 ms / 5,000 ms |
コード長 | 833 bytes |
コンパイル時間 | 3,607 ms |
コンパイル使用メモリ | 277,016 KB |
実行使用メモリ | 13,152 KB |
最終ジャッジ日時 | 2025-04-20 22:50:24 |
合計ジャッジ時間 | 4,381 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 15 |
ソースコード
#include <bits/stdc++.h> #define int long long //#define USE_FREOPEN //#define MUL_TEST #define FILENAME "sequence" using namespace std; bool exist[1000005]; int a[100005],dp[1000005]; void solve() { int n; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i],exist[a[i]] = 1; sort(a + 1,a + n + 1); reverse(a + 1,a + n + 1); int ans = 0; for (int i = 1; i <= n; i++) { for (int j = a[i]; j <= a[1]; j += a[i]) { if (exist[j]) { dp[a[i]] = max(dp[a[i]],dp[j] + 1); } } ans = max(ans,dp[a[i]]); } cout << ans << '\n'; } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); #ifdef USE_FREOPEN freopen(FILENAME ".in","r",stdin); freopen(FILENAME ".out","w",stdout); #endif int _ = 1; #ifdef MUL_TEST cin >> _; #endif while (_--) solve(); _^=_; return 0^_^0; }