結果
問題 | No.1532 Different Products |
ユーザー | Pachicobue |
提出日時 | 2021-06-04 20:44:36 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 524 ms / 4,000 ms |
コード長 | 14,303 bytes |
コンパイル時間 | 2,346 ms |
コンパイル使用メモリ | 213,168 KB |
実行使用メモリ | 317,568 KB |
最終ジャッジ日時 | 2024-04-30 00:22:40 |
合計ジャッジ時間 | 20,393 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 77 ms
53,120 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 1 ms
6,940 KB |
testcase_07 | AC | 3 ms
6,940 KB |
testcase_08 | AC | 4 ms
6,944 KB |
testcase_09 | AC | 30 ms
28,928 KB |
testcase_10 | AC | 103 ms
71,680 KB |
testcase_11 | AC | 78 ms
58,624 KB |
testcase_12 | AC | 239 ms
157,696 KB |
testcase_13 | AC | 145 ms
112,128 KB |
testcase_14 | AC | 418 ms
260,992 KB |
testcase_15 | AC | 22 ms
29,312 KB |
testcase_16 | AC | 89 ms
60,288 KB |
testcase_17 | AC | 88 ms
68,224 KB |
testcase_18 | AC | 67 ms
60,800 KB |
testcase_19 | AC | 236 ms
151,680 KB |
testcase_20 | AC | 421 ms
263,424 KB |
testcase_21 | AC | 130 ms
85,888 KB |
testcase_22 | AC | 156 ms
104,704 KB |
testcase_23 | AC | 89 ms
79,488 KB |
testcase_24 | AC | 383 ms
242,944 KB |
testcase_25 | AC | 198 ms
135,296 KB |
testcase_26 | AC | 27 ms
21,504 KB |
testcase_27 | AC | 176 ms
115,968 KB |
testcase_28 | AC | 131 ms
91,648 KB |
testcase_29 | AC | 119 ms
70,912 KB |
testcase_30 | AC | 235 ms
154,240 KB |
testcase_31 | AC | 244 ms
158,336 KB |
testcase_32 | AC | 274 ms
183,936 KB |
testcase_33 | AC | 212 ms
141,440 KB |
testcase_34 | AC | 358 ms
227,712 KB |
testcase_35 | AC | 272 ms
182,656 KB |
testcase_36 | AC | 320 ms
221,056 KB |
testcase_37 | AC | 60 ms
37,504 KB |
testcase_38 | AC | 352 ms
237,056 KB |
testcase_39 | AC | 307 ms
210,816 KB |
testcase_40 | AC | 321 ms
215,040 KB |
testcase_41 | AC | 476 ms
308,224 KB |
testcase_42 | AC | 411 ms
272,768 KB |
testcase_43 | AC | 432 ms
285,440 KB |
testcase_44 | AC | 486 ms
311,808 KB |
testcase_45 | AC | 515 ms
312,832 KB |
testcase_46 | AC | 491 ms
304,000 KB |
testcase_47 | AC | 509 ms
316,672 KB |
testcase_48 | AC | 503 ms
312,832 KB |
testcase_49 | AC | 513 ms
314,240 KB |
testcase_50 | AC | 515 ms
311,808 KB |
testcase_51 | AC | 508 ms
315,136 KB |
testcase_52 | AC | 504 ms
309,632 KB |
testcase_53 | AC | 515 ms
316,672 KB |
testcase_54 | AC | 503 ms
309,376 KB |
testcase_55 | AC | 524 ms
313,472 KB |
testcase_56 | AC | 503 ms
302,976 KB |
testcase_57 | AC | 515 ms
305,408 KB |
testcase_58 | AC | 512 ms
311,040 KB |
testcase_59 | AC | 471 ms
293,376 KB |
testcase_60 | AC | 505 ms
317,568 KB |
testcase_61 | AC | 2 ms
5,376 KB |
testcase_62 | AC | 2 ms
5,376 KB |
testcase_63 | AC | 492 ms
313,472 KB |
ソースコード
#include <bits/stdc++.h> #pragma region Header using i32 = int; using u32 = unsigned int; using i64 = long long; using u64 = unsigned long long; using i128 = __int128_t; using u128 = __uint128_t; using f64 = double; using f80 = long double; using f128 = __float128; constexpr i32 operator"" _i32(u64 v) { return v; } constexpr i32 operator"" _u32(u64 v) { return v; } constexpr i64 operator"" _i64(u64 v) { return v; } constexpr u64 operator"" _u64(u64 v) { return v; } constexpr f64 operator"" _f64(f80 v) { return v; } constexpr f80 operator"" _f80(f80 v) { return v; } using Istream = std::istream; using Ostream = std::ostream; using Str = std::string; template<typename T> using Lt = std::less<T>; template<typename T> using Gt = std::greater<T>; template<typename T> using IList = std::initializer_list<T>; template<int n> using BSet = std::bitset<n>; template<typename T1, typename T2> using Pair = std::pair<T1, T2>; template<typename... Ts> using Tup = std::tuple<Ts...>; template<typename T, int N> using Arr = std::array<T, N>; template<typename... Ts> using Deq = std::deque<Ts...>; template<typename... Ts> using Set = std::set<Ts...>; template<typename... Ts> using MSet = std::multiset<Ts...>; template<typename... Ts> using USet = std::unordered_set<Ts...>; template<typename... Ts> using UMSet = std::unordered_multiset<Ts...>; template<typename... Ts> using Map = std::map<Ts...>; template<typename... Ts> using MMap = std::multimap<Ts...>; template<typename... Ts> using UMap = std::unordered_map<Ts...>; template<typename... Ts> using UMMap = std::unordered_multimap<Ts...>; template<typename... Ts> using Vec = std::vector<Ts...>; template<typename... Ts> using Stack = std::stack<Ts...>; template<typename... Ts> using Queue = std::queue<Ts...>; template<typename T> using MaxHeap = std::priority_queue<T>; template<typename T> using MinHeap = std::priority_queue<T, Vec<T>, Gt<T>>; using NSec = std::chrono::nanoseconds; using USec = std::chrono::microseconds; using MSec = std::chrono::milliseconds; using Sec = std::chrono::seconds; template<typename T> constexpr T INF = std::numeric_limits<T>::max() / 4; template<typename T> constexpr T PI = T{3.141592653589793238462643383279502884}; template<typename T = u64> constexpr T TEN(const int n) { return n == 0 ? T{1} : TEN<T>(n - 1) * T{10}; } template<typename T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else { return false; } } template<typename T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else { return false; } } template<typename T> constexpr T fdiv(T x, T y) { if (y < T{}) { x = -x, y = -y; } return x >= T{} ? x / y : (x - y + 1) / y; } template<typename T> constexpr T cdiv(T x, T y) { if (y < T{}) { x = -x, y = -y; } return x >= T{} ? (x + y - 1) / y : x / y; } template<typename T, typename I> constexpr T modPower(T v, I n, T mod) { T ans = 1 % mod; for (; n > 0; n >>= 1, (v *= v) %= mod) { if (n % 2 == 1) { (ans *= v) %= mod; } } return ans; } template<typename T, typename I> constexpr T power(T v, I n) { T ans = 1; for (; n > 0; n >>= 1, v *= v) { if (n % 2 == 1) { ans *= v; } } return ans; } template<typename T, typename I> constexpr T power(T v, I n, const T& e) { T ans = e; for (; n > 0; n >>= 1, v *= v) { if (n % 2 == 1) { ans *= v; } } return ans; } template<typename T> Vec<T> operator+=(Vec<T>& vs1, const Vec<T>& vs2) { vs1.insert(vs1.end(), vs2.begin(), vs2.end()); return vs1; } template<typename T> Vec<T> operator+(const Vec<T>& vs1, const Vec<T>& vs2) { auto vs = vs1; vs += vs2; return vs; } template<typename T> void fillAll(Vec<T>& vs, const T& v) { std::fill(vs.begin(), vs.end(), v); } template<typename T, typename C = Lt<T>> void sortAll(Vec<T>& vs, C comp = C{}) { std::sort(vs.begin(), vs.end(), comp); } template<typename T> void reverseAll(Vec<T>& vs) { std::reverse(vs.begin(), vs.end()); } template<typename T> void uniqueAll(Vec<T>& vs) { sortAll(vs); vs.erase(std::unique(vs.begin(), vs.end()), vs.end()); } template<typename T, typename V = T> V sumAll(const Vec<T>& vs) { return std::accumulate(vs.begin(), vs.end(), V{}); } template<typename T> int minInd(const Vec<T>& vs) { return std::min_element(vs.begin(), vs.end()) - vs.begin(); } template<typename T> int maxInd(const Vec<T>& vs) { return std::max_element(vs.begin(), vs.end()) - vs.begin(); } template<typename T> int lbInd(const Vec<T>& vs, const T& v) { return std::lower_bound(vs.begin(), vs.end(), v) - vs.begin(); } template<typename T> int ubInd(const Vec<T>& vs, const T& v) { return std::upper_bound(vs.begin(), vs.end(), v) - vs.begin(); } template<typename T, typename F> Vec<T> genVec(int n, F gen) { Vec<T> ans; std::generate_n(std::back_insert_iterator(ans), n, gen); return ans; } Vec<int> iotaVec(int n, int offset = 0) { Vec<int> ans(n); std::iota(ans.begin(), ans.end(), offset); return ans; } template<typename T> Vec<T> revVec(const Vec<T>& vs) { auto ans = vs; reverseAll(ans); return ans; } Ostream& operator<<(Ostream& os, i128 v) { bool minus = false; if (v < 0) { minus = true, v = -v; } Str ans; if (v == 0) { ans = "0"; } while (v) { ans.push_back('0' + v % 10), v /= 10; } std::reverse(ans.begin(), ans.end()); return os << (minus ? "-" : "") << ans; } Ostream& operator<<(Ostream& os, u128 v) { Str ans; if (v == 0) { ans = "0"; } while (v) { ans.push_back('0' + v % 10), v /= 10; } std::reverse(ans.begin(), ans.end()); return os << ans; } constexpr int popcount(const u64 v) { return v ? __builtin_popcountll(v) : 0; } constexpr int log2p1(const u64 v) { return v ? 64 - __builtin_clzll(v) : 0; } constexpr int lsbp1(const u64 v) { return __builtin_ffsll(v); } constexpr int clog(const u64 v) { return v ? log2p1(v - 1) : 0; } constexpr u64 ceil2(const u64 v) { const int l = clog(v); return (l == 64) ? 0_u64 : (1_u64 << l); } constexpr u64 floor2(const u64 v) { return v ? (1_u64 << (log2p1(v) - 1)) : 0_u64; } constexpr bool ispow2(const u64 v) { return (v > 0) and ((v & (v - 1)) == 0); } constexpr bool btest(const u64 mask, const int ind) { return (mask >> ind) & 1_u64; } template<typename F> struct Fix : F { Fix(F&& f) : F{std::forward<F>(f)} {} template<typename... Args> auto operator()(Args&&... args) const { return F::operator()(*this, std::forward<Args>(args)...); } }; class irange { private: struct itr { itr(int start = 0, int step = 1) : m_cnt{start}, m_step{step} {} bool operator!=(const itr& it) const { return m_cnt != it.m_cnt; } int operator*() { return m_cnt; } itr& operator++() { m_cnt += m_step; return *this; } int m_cnt, m_step; }; int m_start, m_end, m_step; public: irange(int start, int end, int step = 1) { assert(step != 0); const int d = std::abs(step); const int l = (step > 0 ? start : end); const int r = (step > 0 ? end : start); int n = (r - l) / d + ((r - l) % d ? 1 : 0); if (l >= r) { n = 0; } m_start = start; m_end = start + step * n; m_step = step; } itr begin() const { return itr{m_start, m_step}; } itr end() const { return itr{m_end, m_step}; } }; irange rep(int end) { return irange(0, end, 1); } irange per(int rend) { return irange(rend - 1, -1, -1); } #pragma COMMENT("[REFS] Xoshiro: https://prng.di.unimi.it") namespace xoshiro_impl { u64 x; u64 next() { uint64_t z = (x += 0x9e3779b97f4a7c15); z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9; z = (z ^ (z >> 27)) * 0x94d049bb133111eb; return z ^ (z >> 31); } } class Xoshiro32 { public: using result_type = u32; using T = result_type; Xoshiro32(T seed = 0) { xoshiro_impl::x = seed; s[0] = xoshiro_impl::next(); s[1] = xoshiro_impl::next(); s[2] = xoshiro_impl::next(); s[3] = xoshiro_impl::next(); } static constexpr T min() { return std::numeric_limits<T>::min(); } static constexpr T max() { return std::numeric_limits<T>::max(); } T operator()() { return next(); } private: static constexpr T rotl(const T x, int k) { return (x << k) | (x >> (32 - k)); } T next() { const T ans = rotl(s[1] * 5, 7) * 9; const T t = s[1] << 9; s[2] ^= s[0]; s[3] ^= s[1]; s[1] ^= s[2]; s[0] ^= s[3]; s[2] ^= t; s[3] = rotl(s[3], 11); return ans; } T s[4]; }; class Xoshiro64 { public: using result_type = u64; using T = result_type; Xoshiro64(T seed = 0) { xoshiro_impl::x = seed; s[0] = xoshiro_impl::next(); s[1] = xoshiro_impl::next(); s[2] = xoshiro_impl::next(); s[3] = xoshiro_impl::next(); } static constexpr T min() { return std::numeric_limits<T>::min(); } static constexpr T max() { return std::numeric_limits<T>::max(); } T operator()() { return next(); } private: static constexpr T rotl(const T x, int k) { return (x << k) | (x >> (64 - k)); } T next() { const T ans = rotl(s[1] * 5, 7) * 9; const T t = s[1] << 17; s[2] ^= s[0]; s[3] ^= s[1]; s[1] ^= s[2]; s[0] ^= s[3]; s[2] ^= t; s[3] = rotl(s[3], 45); return ans; } T s[4]; }; template<typename Rng> class RNG { public: using result_type = typename Rng::result_type; using T = result_type; static constexpr T min() { return Rng::min(); } static constexpr T max() { return Rng::max(); } RNG() : RNG(std::random_device{}()) {} RNG(T seed) : m_rng(seed) {} T operator()() { return m_rng(); } template<typename T> T val(T min, T max) { return std::uniform_int_distribution<T>(min, max)(m_rng); } template<typename T> Pair<T, T> pair(T min, T max) { return std::minmax({val<T>(min, max), val<T>(min, max)}); } template<typename T> Vec<T> vec(int n, T min, T max) { return genVec<T>(n, [&]() { return val<T>(min, max); }); } template<typename T> Vec<Vec<T>> vvec(int n, int m, T min, T max) { return genVec<Vec<T>>(n, [&]() { return vec(m, min, max); }); } private: Rng m_rng; }; RNG<std::mt19937> rng; RNG<std::mt19937_64> rng64; RNG<Xoshiro32> rng_xo; RNG<Xoshiro64> rng_xo64; class Scanner { public: Scanner(Istream& is = std::cin) : m_is{is} { m_is.tie(nullptr)->sync_with_stdio(false); } template<typename T> T val() { T v; return m_is >> v, v; } template<typename T> T val(T offset) { return val<T>() - offset; } template<typename T> Vec<T> vec(int n) { return genVec<T>(n, [&]() { return val<T>(); }); } template<typename T> Vec<T> vec(int n, T offset) { return genVec<T>(n, [&]() { return val<T>(offset); }); } template<typename T> Vec<Vec<T>> vvec(int n, int m) { return genVec<Vec<T>>(n, [&]() { return vec<T>(m); }); } template<typename T> Vec<Vec<T>> vvec(int n, int m, const T offset) { return genVec<Vec<T>>(n, [&]() { return vec<T>(m, offset); }); } template<typename... Args> auto tup() { return Tup<Args...>{val<Args>()...}; } template<typename... Args> auto tup(const Args&... offsets) { return Tup<Args...>{val<Args>(offsets)...}; } private: Istream& m_is; }; Scanner in; class Printer { public: Printer(Ostream& os = std::cout) : m_os{os} { m_os << std::fixed << std::setprecision(15); } template<typename... Args> int operator()(const Args&... args) { dump(args...); return 0; } template<typename... Args> int ln(const Args&... args) { dump(args...), m_os << '\n'; return 0; } template<typename... Args> int el(const Args&... args) { dump(args...), m_os << std::endl; return 0; } private: template<typename T> void dump(const T& v) { m_os << v; } template<typename T> void dump(const Vec<T>& vs) { for (const int i : rep(vs.size())) { m_os << (i ? " " : ""), dump(vs[i]); } } template<typename T> void dump(const Vec<Vec<T>>& vss) { for (const int i : rep(vss.size())) { m_os << (i ? "" : "\n"), dump(vss[i]); } } template<typename T, typename... Ts> int dump(const T& v, const Ts&... args) { dump(v), m_os << ' ', dump(args...); return 0; } Ostream& m_os; }; Printer out; template<typename T, int n, int i = 0> auto ndVec(int const (&szs)[n], const T x = T{}) { if constexpr (i == n) { return x; } else { return std::vector(szs[i], ndVec<T, n, i + 1>(szs, x)); } } #pragma endregion int main() { const auto [N, K] = in.tup<int, i64>(); int num = 0; i64 sqrt = 0; for (i64 i = 1; i * i <= K; i++) { num++; sqrt = i; if (i * i != K) { num++; } } auto dec = [&, K = K](i64 max) { if (max <= sqrt) { return max - 1; } else { return num - (K / max); } }; void(0); void(0); void(0); auto memo = ndVec({N, num}, 0_u64); const u64 ans = Fix([&](auto f, int i, i64 max) -> u64 { if (i == 0) { return 2; } const int id = dec(max); if (memo[i][id] != 0) { return memo[i][id]; } i64 ans = f(i - 1, max); if (max >= i + 1) { ans += f(i - 1, max / (i + 1)); } return memo[i][id] = ans; })(N - 1, K); out.ln(ans - 1); return 0; }