結果
問題 | No.979 Longest Divisor Sequence |
ユーザー | fine |
提出日時 | 2020-01-31 21:49:42 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 571 ms / 2,000 ms |
コード長 | 775 bytes |
コンパイル時間 | 1,668 ms |
コンパイル使用メモリ | 173,236 KB |
実行使用メモリ | 208,412 KB |
最終ジャッジ日時 | 2023-10-17 09:22:51 |
合計ジャッジ時間 | 5,814 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 166 ms
205,232 KB |
testcase_01 | AC | 167 ms
205,232 KB |
testcase_02 | AC | 170 ms
205,232 KB |
testcase_03 | AC | 168 ms
205,232 KB |
testcase_04 | AC | 167 ms
205,232 KB |
testcase_05 | AC | 168 ms
205,232 KB |
testcase_06 | AC | 166 ms
205,232 KB |
testcase_07 | AC | 169 ms
205,232 KB |
testcase_08 | AC | 167 ms
205,232 KB |
testcase_09 | AC | 166 ms
205,232 KB |
testcase_10 | AC | 167 ms
205,260 KB |
testcase_11 | AC | 166 ms
205,260 KB |
testcase_12 | AC | 167 ms
205,260 KB |
testcase_13 | AC | 208 ms
208,412 KB |
testcase_14 | AC | 571 ms
207,092 KB |
testcase_15 | AC | 252 ms
205,508 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; deque<int> memo[300005]; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin >> n; int maxa = 0; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; memo[a[i]].push_back(i); maxa = max(maxa, a[i]); } vector<int> dp(n, 1); for (int i = 0; i < n; ++i) { memo[a[i]].pop_front(); for (int j = a[i] * 2; j <= maxa; j += a[i]) { if (!memo[j].empty()) { dp[memo[j].front()] = max(dp[memo[j].front()], dp[i] + 1); } } } int ans = 0; for (int i = 0; i < n; ++i) { ans = max(ans, dp[i]); } cout << ans << "\n"; return 0; }