結果

問題 No.2500 Products in a Range
ユーザー nono00nono00
提出日時 2023-10-13 21:55:01
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,511 bytes
コンパイル時間 3,204 ms
コンパイル使用メモリ 258,076 KB
実行使用メモリ 4,476 KB
最終ジャッジ日時 2023-10-13 21:55:11
合計ジャッジ時間 5,275 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 1 ms
4,352 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 3 ms
4,352 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 1 ms
4,352 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 1 ms
4,352 KB
testcase_16 AC 3 ms
4,348 KB
testcase_17 AC 2 ms
4,352 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,352 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 3 ms
4,352 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 3 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 WA -
testcase_32 AC 1 ms
4,348 KB
testcase_33 AC 2 ms
4,348 KB
testcase_34 AC 2 ms
4,348 KB
testcase_35 AC 2 ms
4,348 KB
testcase_36 AC 1 ms
4,348 KB
testcase_37 AC 1 ms
4,352 KB
testcase_38 AC 2 ms
4,352 KB
testcase_39 AC 1 ms
4,348 KB
testcase_40 AC 1 ms
4,348 KB
testcase_41 AC 1 ms
4,352 KB
testcase_42 AC 2 ms
4,348 KB
testcase_43 AC 2 ms
4,348 KB
testcase_44 AC 2 ms
4,352 KB
testcase_45 AC 1 ms
4,348 KB
testcase_46 AC 2 ms
4,348 KB
testcase_47 AC 2 ms
4,348 KB
testcase_48 AC 1 ms
4,352 KB
testcase_49 WA -
testcase_50 AC 3 ms
4,348 KB
testcase_51 AC 2 ms
4,352 KB
testcase_52 AC 2 ms
4,352 KB
testcase_53 AC 2 ms
4,352 KB
testcase_54 AC 1 ms
4,348 KB
testcase_55 AC 2 ms
4,348 KB
testcase_56 AC 2 ms
4,348 KB
testcase_57 AC 2 ms
4,348 KB
testcase_58 AC 2 ms
4,348 KB
testcase_59 AC 2 ms
4,356 KB
testcase_60 AC 1 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

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