-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmineira2024J.cpp
More file actions
39 lines (31 loc) · 807 Bytes
/
Copy pathmineira2024J.cpp
File metadata and controls
39 lines (31 loc) · 807 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
Maratona Mineira 2024 - J - Jazz
https://codeforces.com/group/YgJmumGtHD/contest/528947/problem/I
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fastio ios::sync_with_stdio(0); cin.tie(0);
int main() {
fastio
const int V = 2e5 + 1;
int n; cin >> n;
vector<int> cnt(V, 0); // quantas vezes o valor aparece
for (int i = 0; i < n; i++) {
int x; cin >> x;
cnt[x]++;
}
vector<int> dp(V, 0); // tamanho da maior cadeia terminando na posição
int ans = 0;
for (int v = 1; v < V; v++) {
if (cnt[v] == 0) continue;
dp[v] = max(dp[v], 1);
for (int mul = 2 * v; mul < V; mul += v) {
if (cnt[mul] == 0) continue;
dp[mul] = max(dp[mul], dp[v] + 1);
}
ans = max(ans, dp[v]);
}
cout << ans << '\n';
return 0;
}