結果
問題 | No.979 Longest Divisor Sequence |
ユーザー | risujiroh |
提出日時 | 2020-01-31 22:11:50 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 837 bytes |
コンパイル時間 | 1,585 ms |
コンパイル使用メモリ | 172,492 KB |
実行使用メモリ | 31,556 KB |
最終ジャッジ日時 | 2023-10-17 10:00:45 |
合計ジャッジ時間 | 5,577 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 185 ms
30,228 KB |
testcase_01 | AC | 194 ms
30,228 KB |
testcase_02 | AC | 192 ms
30,228 KB |
testcase_03 | AC | 208 ms
30,228 KB |
testcase_04 | AC | 196 ms
30,228 KB |
testcase_05 | AC | 196 ms
30,228 KB |
testcase_06 | AC | 211 ms
30,228 KB |
testcase_07 | AC | 192 ms
30,228 KB |
testcase_08 | AC | 190 ms
30,228 KB |
testcase_09 | AC | 193 ms
30,228 KB |
testcase_10 | AC | 190 ms
30,228 KB |
testcase_11 | AC | 191 ms
30,228 KB |
testcase_12 | WA | - |
testcase_13 | AC | 201 ms
31,480 KB |
testcase_14 | WA | - |
testcase_15 | AC | 196 ms
30,492 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; auto chmax = [](auto&& l, auto r) { return l < r ? l = r, 1 : 0; }; constexpr int lim = 3e5, th = 512; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin >> n; vector<int> a(n); for_each(begin(a), end(a), [](int& e) { cin >> e; }); reverse(begin(a), end(a)); vector<vector<int>> ds(lim + 1); for (int d = 1; d < th; ++d) { for (int i = 2 * d; i <= lim; i += d) { ds[i].push_back(d); } } vector<int> dp(lim + 1), m(th); for (int e : a) { int mx = -1; if (e < th) { mx = m[e]; } else { for (int i = 2 * e; i <= lim; i += e) { chmax(mx, dp[i]); } } chmax(dp[e], mx + 1); for (int d : ds[e]) { chmax(m[d], dp[e]); } } cout << *max_element(begin(dp), end(dp)) << '\n'; }