結果
問題 |
No.2218 Multiple LIS
|
ユーザー |
![]() |
提出日時 | 2023-08-29 11:05:23 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 84 ms / 3,000 ms |
コード長 | 662 bytes |
コンパイル時間 | 1,767 ms |
コンパイル使用メモリ | 195,616 KB |
最終ジャッジ日時 | 2025-02-16 15:30:44 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 39 |
ソースコード
#include <bits/stdc++.h> using namespace std; using LL = long long; const int MAXN = 1e5 + 3; int n; int a[MAXN]; int dp[MAXN]; vector<int> s[MAXN]; int main(){ ios::sync_with_stdio(0), cin.tie(0); cin >> n; for(int i = 1; i <= n; i++){ cin >> a[i]; if(s[a[i]].size() > 0) continue; for(int j = 1; j * j <= a[i]; j++){ if(a[i] % j == 0){ s[a[i]].push_back(j); if(a[i] / j != j) s[a[i]].push_back(a[i] / j); } } } int ans = 0; for(int i = n; i >= 1; i--){ dp[a[i]]++; ans = max(ans, dp[a[i]]); for(int j : s[a[i]]){ dp[j] = max(dp[j], dp[a[i]]); } } cout << ans; return 0; }