結果
問題 | No.2500 Products in a Range |
ユーザー |
![]() |
提出日時 | 2023-09-02 17:19:36 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 76 ms / 2,000 ms |
コード長 | 1,016 bytes |
コンパイル時間 | 1,298 ms |
コンパイル使用メモリ | 106,836 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-15 13:54:48 |
合計ジャッジ時間 | 3,672 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 61 |
ソースコード
#include <algorithm> #include <cassert> #include <cstdint> #include <iostream> #include <vector> // <AC> // O(n^2) 時間 int main() { constexpr int kMaxN = 5000, kMinA = -1000000000, kMaxA = 1000000000; int n, l, r; std::cin >> n >> l >> r; assert(1 <= n && n <= kMaxN && kMinA <= l && l <= r && r <= kMaxA); std::vector<std::int64_t> a(n); for (int i = 0; i < n; ++i) { std::cin >> a[i]; assert(kMinA <= a[i] && a[i] <= kMaxA); } std::ranges::sort(a); std::vector<int> p(n, n), q(n, -1); for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { if (l <= a[i] * a[j] && a[i] * a[j] <= r) { if (p[i] == n) p[i] = j; q[i] = j; } } } int ans = 1; for (int i = 0; i < n; ++i) { for (int j = std::max(p[i], i + 1); j <= q[i]; ++j) { const int inside = std::min({q[i], q[j], j - 1}) - std::max({p[i], p[j], i + 1}) + 1; ans = std::max(ans, 2 + std::max(inside, 0)); } } std::cout << ans << '\n'; return 0; }