結果
問題 | No.979 Longest Divisor Sequence |
ユーザー | noshi91 |
提出日時 | 2019-10-07 21:46:36 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 182 ms / 2,000 ms |
コード長 | 901 bytes |
コンパイル時間 | 614 ms |
コンパイル使用メモリ | 75,836 KB |
実行使用メモリ | 18,404 KB |
最終ジャッジ日時 | 2023-08-04 19:39:43 |
合計ジャッジ時間 | 1,940 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 10 ms
11,344 KB |
testcase_01 | AC | 9 ms
11,544 KB |
testcase_02 | AC | 15 ms
11,628 KB |
testcase_03 | AC | 14 ms
11,300 KB |
testcase_04 | AC | 15 ms
11,364 KB |
testcase_05 | AC | 14 ms
11,368 KB |
testcase_06 | AC | 17 ms
11,412 KB |
testcase_07 | AC | 14 ms
11,356 KB |
testcase_08 | AC | 15 ms
11,428 KB |
testcase_09 | AC | 15 ms
11,428 KB |
testcase_10 | AC | 20 ms
11,296 KB |
testcase_11 | AC | 21 ms
11,292 KB |
testcase_12 | AC | 20 ms
11,444 KB |
testcase_13 | AC | 54 ms
14,476 KB |
testcase_14 | AC | 182 ms
18,404 KB |
testcase_15 | AC | 83 ms
14,192 KB |
ソースコード
#include <algorithm> #include <iostream> #include <vector> int main() { static constexpr int ALim = 300001; int n; std::cin >> n; std::vector<int> a(n); for (auto& e : a) { std::cin >> e; } std::vector<std::vector<int>> rev(ALim); std::vector<int> dp(ALim, -1); for (int i = 0; i != n; ++i) { rev[a[i]].push_back(i); dp[a[i]] = i; } for (int len = 1;; ++len) { for (int i = 1; i != ALim; ++i) { int max = -1; for (int j = i + i; j < ALim; j += i) { max = std::max(max, dp[j]); } int j = 0; while (j != static_cast<int>(rev[i].size()) && rev[i][j] < max) { ++j; } if (j == 0) { dp[i] = -1; } else { dp[i] = rev[i][j-1]; } } if (std::all_of(dp.cbegin(), dp.cend(), [](int x) { return x == -1; })) { std::cout << len << std::endl; return 0; } } }