結果

問題 No.2218 Multiple LIS
ユーザー vjudge1
提出日時 2023-08-29 11:05:06
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 92 ms / 3,000 ms
コード長 662 bytes
コンパイル時間 3,167 ms
コンパイル使用メモリ 248,292 KB
実行使用メモリ 11,108 KB
最終ジャッジ日時 2024-12-30 23:18:53
合計ジャッジ時間 5,114 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0