結果

問題 No.2500 Products in a Range
ユーザー nono00
提出日時 2023-10-13 21:55:01
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,511 bytes
コンパイル時間 3,172 ms
コンパイル使用メモリ 260,024 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-15 17:35:05
合計ジャッジ時間 4,695 ms
ジャッジサーバーID
(参考情報)
judge2 / judge6
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 59 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

namespace nono {

struct Init {};

void solve([[maybe_unused]] const Init& init) {
    long long n, l, r;
    std::cin >> n >> l >> r;
    std::vector<long long> a(n);
    for (int i = 0; i < n; i++) std::cin >> a[i];
    std::ranges::sort(a);
    int mid = std::distance(a.begin(), std::ranges::lower_bound(a, 0));
    int right = 0;
    int ans = 0;

    auto ok = [&](int left, int right) {
        if (right - left <= 1) return true;
        if (right <= mid) {
            if (r < a[left] * a[left + 1]) return false;
            if (a[right - 1] * a[right - 2] < l) return false;
        } else if (mid <= left) {
            if (a[right - 1] * a[right - 2] > r) return false;
            if (a[left] * a[left + 1] < l) return false;
        } else {
            if (a[right - 1] * a[left] < l) return false;
            if (mid - left >= 2) {
                if (a[left] * a[left + 1] > r) return false;
            }
            if (right - mid >= 2) {
                if (a[right - 1] * a[right - 2] > r) return false;
            }
        }
        return true;
    };

    for (int left = 0; left < n; left++) {
        if (right < left) right = left;
        while (right < n && ok(left, right + 1)) {
            right++;
        }
        ans = std::max(ans, right - left);
    }
    std::cout << ans << std::endl;
}

}  //  namespace nono

int main() {
    std::cin.tie(0)->sync_with_stdio(0);

    int t = 1;
    nono::Init init;

    while (t--) nono::solve(init);
}
0