結果

問題 No.1532 Different Products
ユーザー keijakkeijak
提出日時 2021-06-04 21:30:00
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 3,761 bytes
コンパイル時間 8,241 ms
コンパイル使用メモリ 410,208 KB
実行使用メモリ 814,588 KB
最終ジャッジ日時 2023-08-12 11:45:35
合計ジャッジ時間 18,822 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 MLE -
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 40 ms
17,060 KB
testcase_10 MLE -
testcase_11 AC 1,029 ms
280,780 KB
testcase_12 MLE -
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 -- -
testcase_61 -- -
testcase_62 -- -
testcase_63 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define REP_(i, a_, b_, a, b, ...) \
  for (int i = (a), END_##i = (b); i < END_##i; ++i)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define ALL(x) std::begin(x), std::end(x)
using i64 = long long;

#include <boost/multiprecision/cpp_int.hpp>
using Int = boost::multiprecision::checked_int128_t;
// using i256 = boost::multiprecision::int256_t;
// using i512 = boost::multiprecision::int512_t;
// using i1024 = boost::multiprecision::int1024_t;
// using Int = boost::multiprecision::cpp_int;

template <typename T, typename U>
inline bool chmax(T &a, U b) {
  return a < b and ((a = std::move(b)), true);
}
template <typename T, typename U>
inline bool chmin(T &a, U b) {
  return a > b and ((a = std::move(b)), true);
}
template <typename T>
inline int ssize(const T &a) {
  return (int)std::size(a);
}

template <typename T>
std::istream &operator>>(std::istream &is, std::vector<T> &a) {
  for (auto &x : a) is >> x;
  return is;
}
template <typename T, typename U>
std::ostream &operator<<(std::ostream &os, const std::pair<T, U> &a) {
  return os << "(" << a.first << ", " << a.second << ")";
}
template <typename Container>
std::ostream &print_seq(const Container &a, std::string_view sep = " ",
                        std::string_view ends = "\n",
                        std::ostream &os = std::cout) {
  auto b = std::begin(a), e = std::end(a);
  for (auto it = std::begin(a); it != e; ++it) {
    if (it != b) os << sep;
    os << *it;
  }
  return os << ends;
}
template <typename T, typename = void>
struct is_iterable : std::false_type {};
template <typename T>
struct is_iterable<T, std::void_t<decltype(std::begin(std::declval<T>())),
                                  decltype(std::end(std::declval<T>()))>>
    : std::true_type {};

template <typename T, typename = std::enable_if_t<
                          is_iterable<T>::value &&
                          !std::is_same<T, std::string_view>::value &&
                          !std::is_same<T, std::string>::value>>
std::ostream &operator<<(std::ostream &os, const T &a) {
  return print_seq(a, ", ", "", (os << "{")) << "}";
}

#ifdef ENABLE_DEBUG
#include "debug_dump.hpp"
#else
#define DUMP(...)
#endif

using namespace std;

auto solve() {
  i64 n, K;
  cin >> n >> K;
  vector<int> va, vb;
  REP(i, 1, n + 1) {
    if (i & 1) {
      va.push_back(i);
    } else {
      vb.push_back(i);
    }
  }

  auto f = [&](auto &f, const vector<int> &v, int i, i64 acc,
               vector<i64> &mp) -> void {
    const int m = ssize(v);
    if (i == m) {
      return;
    }
    f(f, v, i + 1, acc, mp);

    acc *= v[i];
    if (acc <= K) {
      mp.push_back(acc);
      //++mp[acc];
      f(f, v, i + 1, acc, mp);
    }
  };
  // map<i64, i64> ma, mb;
  vector<i64> ma, mb;
  ma.reserve(1000000);
  mb.reserve(1000000);
  ma.push_back(1);
  mb.push_back(1);
  //   ma[1] = 1;
  //   mb[1] = 1;
  f(f, va, 0, 1, ma);
  f(f, vb, 0, 1, mb);
  sort(ALL(ma));
  sort(ALL(mb));
  DUMP(ma);
  DUMP(mb);
  vector<pair<i64, i64>> ca(ssize(ma) + 1);
  {
    int i = 0;
    for (auto k : ma) {
      ++i;
      ca[i] = {k, 1};
      ca[i].second += ca[i - 1].second;
    }
    // i = 0;
    // for (auto k : mb) {
    //   cb[i] = {k, 1};
    //   ++i;
    //   // cb[i].second += cb[i - 1].second;
    // }
  }
  ca.emplace_back(K + 1, 0);
  DUMP(ca);
  DUMP(cb);
  i64 ans = 0;
  {
    int i = 1, j = ssize(mb) - 1;
    for (; j >= 0; --j) {
      auto x2 = mb[j];
      while (i < ssize(ca) and ca[i].first * x2 <= K) {
        ++i;
      }
      ans += ca[i - 1].second;
      DUMP(x2, ca[i - 1].second, ans);
    }
  }
  --ans;
  return ans;
}

int main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr);
  cout << solve() << "\n";
}
0