結果

問題 No.2500 Products in a Range
ユーザー nono00nono00
提出日時 2023-10-13 22:43:17
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 2,704 bytes
コンパイル時間 3,132 ms
コンパイル使用メモリ 259,804 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-13 22:43:29
合計ジャッジ時間 5,794 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 4 ms
4,348 KB
testcase_08 AC 22 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,352 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 15 ms
4,348 KB
testcase_15 AC 2 ms
4,356 KB
testcase_16 AC 40 ms
4,352 KB
testcase_17 AC 19 ms
4,348 KB
testcase_18 AC 21 ms
4,348 KB
testcase_19 AC 50 ms
4,348 KB
testcase_20 AC 57 ms
4,352 KB
testcase_21 AC 4 ms
4,352 KB
testcase_22 AC 31 ms
4,352 KB
testcase_23 AC 30 ms
4,348 KB
testcase_24 AC 32 ms
4,348 KB
testcase_25 AC 3 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 3 ms
4,352 KB
testcase_28 AC 48 ms
4,352 KB
testcase_29 AC 10 ms
4,348 KB
testcase_30 AC 8 ms
4,348 KB
testcase_31 AC 2 ms
4,352 KB
testcase_32 AC 3 ms
4,348 KB
testcase_33 AC 2 ms
4,348 KB
testcase_34 AC 3 ms
4,348 KB
testcase_35 AC 2 ms
4,352 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 1 ms
4,348 KB
testcase_38 AC 2 ms
4,348 KB
testcase_39 AC 1 ms
4,352 KB
testcase_40 AC 2 ms
4,348 KB
testcase_41 AC 2 ms
4,348 KB
testcase_42 AC 1 ms
4,348 KB
testcase_43 AC 1 ms
4,352 KB
testcase_44 AC 2 ms
4,348 KB
testcase_45 AC 2 ms
4,356 KB
testcase_46 AC 13 ms
4,352 KB
testcase_47 AC 3 ms
4,352 KB
testcase_48 AC 1 ms
4,348 KB
testcase_49 AC 1 ms
4,348 KB
testcase_50 AC 18 ms
4,348 KB
testcase_51 AC 14 ms
4,348 KB
testcase_52 AC 41 ms
4,352 KB
testcase_53 AC 5 ms
4,348 KB
testcase_54 AC 2 ms
4,352 KB
testcase_55 AC 20 ms
4,348 KB
testcase_56 AC 23 ms
4,352 KB
testcase_57 AC 8 ms
4,352 KB
testcase_58 AC 8 ms
4,348 KB
testcase_59 AC 55 ms
4,352 KB
testcase_60 AC 3 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;
            }
            if (right - mid < 2 && mid - left < 2) {
                if (r < a[right - 1] * a[left]) return false;
            }
        }
        return true;
    };

    for (int left = 0; left < n; left++) {
        if (right < left) right = left;
        while (right < n && ok(left, right + 1)) {
            right++;
        }
        bool flag = false;
        for (int i = 0; i < n; i++) {
            if (left <= i && i < right) continue;

            if (a[i] == 0) {
                if (l <= 0 && 0 <= r) {
                    flag = true;
                    break;
                }
            } else if (a[i] > 0) {
                if (right <= mid) {
                    if (a[i] * a[left] < l) continue;
                    if (a[i] * a[right - 1] > r) continue;
                } else {
                    if (a[i] * a[left] < l) continue;
                    if (a[i] * a[right - 1] > r) continue;
                }
                flag = true;
                break;
            } else {
                if (right <= mid) {
                    if (a[i] * a[left] > r) continue;
                    if (a[i] * a[right - 1] < l) continue;
                } else {
                    if (a[i] * a[left] > r) continue;
                    if (a[i] * a[right - 1] < l) continue;
                }
                flag = true;
                break;
            }
        }
        ans = std::max(ans, right - left + flag);
    }
    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