結果

問題 No.2500 Products in a Range
ユーザー 👑 emthrmemthrm
提出日時 2023-09-02 19:14:13
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,155 bytes
コンパイル時間 1,101 ms
コンパイル使用メモリ 105,880 KB
実行使用メモリ 8,752 KB
最終ジャッジ日時 2023-09-03 00:20:10
合計ジャッジ時間 5,995 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <cassert>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// <TLE>
// O(n^3) 時間
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);

  int ans = 1;
  for (int i = 0; i < n; ++i) {
    int j = i + 1;
    for (; j < n; ++j) {
      if (!std::all_of(std::next(a.begin(), i), std::next(a.begin(), j),
                       [l, r, &a, j](const std::int64_t x) -> bool {
                         return l <= x * a[j] && x * a[j] <= r;
                       })) {
        break;
      }
    }
    ans = std::max(ans, j - i);
  }
  if (ans == 1) {
    for (int i = 0; ans == 1 && i < n; ++i) {
      for (int j = i + 1; j < n; ++j) {
        if (l <= a[i] * a[j] && a[i] * a[j] <= r) {
          ans = 2;
          break;
        }
      }
    }
  }
  std::cout << ans << '\n';
  return 0;
}
0