QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#308063 | #8009. Growing Sequences | AMATSUKAZE (Makoto Watanabe, Hiroto Yano, Shu Nagashima) | AC ✓ | 0ms | 3844kb | C++20 | 15.5kb | 2024-01-19 14:53:03 | 2024-01-19 14:53:04 |
Judging History
answer
#line 1 "template/template.hpp"
#include <algorithm>
#include <bit>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <numbers>
#include <numeric>
#include <optional>
#include <queue>
#include <random>
#include <ranges>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n)-1); i >= (int)(a); i--)
#define Rep(i, a, n) for (i64 i = (i64)(a); i < (i64)(n); i++)
#define RRep(i, a, n) for (i64 i = ((i64)(n)-i64(1)); i >= (i64)(a); i--)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#line 2 "template/debug_template.hpp"
#line 4 "template/debug_template.hpp"
namespace ebi {
#ifdef LOCAL
#define debug(...) \
std::cerr << "LINE: " << __LINE__ << " [" << #__VA_ARGS__ << "]:", \
debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
void debug_out() {
std::cerr << std::endl;
}
template <typename Head, typename... Tail> void debug_out(Head h, Tail... t) {
std::cerr << " " << h;
if (sizeof...(t) > 0) std::cerr << " :";
debug_out(t...);
}
} // namespace ebi
#line 2 "template/int_alias.hpp"
#line 4 "template/int_alias.hpp"
namespace ebi {
using ld = long double;
using std::size_t;
using i8 = std::int8_t;
using u8 = std::uint8_t;
using i16 = std::int16_t;
using u16 = std::uint16_t;
using i32 = std::int32_t;
using u32 = std::uint32_t;
using i64 = std::int64_t;
using u64 = std::uint64_t;
using i128 = __int128_t;
using u128 = __uint128_t;
} // namespace ebi
#line 2 "template/io.hpp"
#line 7 "template/io.hpp"
namespace ebi {
template <typename T1, typename T2>
std::ostream &operator<<(std::ostream &os, const std::pair<T1, T2> &pa) {
return os << pa.first << " " << pa.second;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &os, std::pair<T1, T2> &pa) {
return os >> pa.first >> pa.second;
}
template <typename T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &vec) {
for (std::size_t i = 0; i < vec.size(); i++)
os << vec[i] << (i + 1 == vec.size() ? "" : " ");
return os;
}
template <typename T>
std::istream &operator>>(std::istream &os, std::vector<T> &vec) {
for (T &e : vec) std::cin >> e;
return os;
}
template <typename T>
std::ostream &operator<<(std::ostream &os, const std::optional<T> &opt) {
if (opt) {
os << opt.value();
} else {
os << "invalid value";
}
return os;
}
void fast_io() {
std::cout << std::fixed << std::setprecision(15);
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
}
} // namespace ebi
#line 2 "template/utility.hpp"
#line 5 "template/utility.hpp"
#line 7 "template/utility.hpp"
namespace ebi {
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> T safe_ceil(T a, T b) {
if (a % b == 0)
return a / b;
else if (a >= 0)
return (a / b) + 1;
else
return -((-a) / b);
}
template <class T> T safe_floor(T a, T b) {
if (a % b == 0)
return a / b;
else if (a >= 0)
return a / b;
else
return -((-a) / b) - 1;
}
constexpr i64 LNF = std::numeric_limits<i64>::max() / 4;
constexpr int INF = std::numeric_limits<int>::max() / 2;
const std::vector<int> dy = {1, 0, -1, 0, 1, 1, -1, -1};
const std::vector<int> dx = {0, 1, 0, -1, 1, -1, 1, -1};
} // namespace ebi
#line 2 "a.cpp"
#line 2 "modint/modint.hpp"
#line 5 "modint/modint.hpp"
#line 2 "modint/base.hpp"
#include <concepts>
#line 6 "modint/base.hpp"
namespace ebi {
template <class T>
concept Modint = requires(T a, T b) {
a + b;
a - b;
a * b;
a / b;
a.inv();
a.val();
a.pow(std::declval<long long>());
T::mod();
};
template <Modint mint> std::istream &operator>>(std::istream &os, mint &a) {
long long x;
os >> x;
a = x;
return os;
}
template <Modint mint>
std::ostream &operator<<(std::ostream &os, const mint &a) {
return os << a.val();
}
} // namespace ebi
#line 7 "modint/modint.hpp"
namespace ebi {
template <int m> struct static_modint {
private:
using modint = static_modint;
public:
static constexpr int mod() {
return m;
}
static constexpr modint raw(int v) {
modint x;
x._v = v;
return x;
}
constexpr static_modint() : _v(0) {}
constexpr static_modint(long long v) {
v %= (long long)umod();
if (v < 0) v += (long long)umod();
_v = (unsigned int)v;
}
constexpr unsigned int val() const {
return _v;
}
constexpr unsigned int value() const {
return val();
}
constexpr modint &operator++() {
_v++;
if (_v == umod()) _v = 0;
return *this;
}
constexpr modint &operator--() {
if (_v == 0) _v = umod();
_v--;
return *this;
}
constexpr modint operator++(int) {
modint res = *this;
++*this;
return res;
}
constexpr modint operator--(int) {
modint res = *this;
--*this;
return res;
}
constexpr modint &operator+=(const modint &rhs) {
_v += rhs._v;
if (_v >= umod()) _v -= umod();
return *this;
}
constexpr modint &operator-=(const modint &rhs) {
_v -= rhs._v;
if (_v >= umod()) _v += umod();
return *this;
}
constexpr modint &operator*=(const modint &rhs) {
unsigned long long x = _v;
x *= rhs._v;
_v = (unsigned int)(x % (unsigned long long)umod());
return *this;
}
constexpr modint &operator/=(const modint &rhs) {
return *this = *this * rhs.inv();
}
constexpr modint operator+() const {
return *this;
}
constexpr modint operator-() const {
return modint() - *this;
}
constexpr modint pow(long long n) const {
assert(0 <= n);
modint x = *this, res = 1;
while (n) {
if (n & 1) res *= x;
x *= x;
n >>= 1;
}
return res;
}
constexpr modint inv() const {
assert(_v);
return pow(umod() - 2);
}
friend modint operator+(const modint &lhs, const modint &rhs) {
return modint(lhs) += rhs;
}
friend modint operator-(const modint &lhs, const modint &rhs) {
return modint(lhs) -= rhs;
}
friend modint operator*(const modint &lhs, const modint &rhs) {
return modint(lhs) *= rhs;
}
friend modint operator/(const modint &lhs, const modint &rhs) {
return modint(lhs) /= rhs;
}
friend bool operator==(const modint &lhs, const modint &rhs) {
return lhs.val() == rhs.val();
}
friend bool operator!=(const modint &lhs, const modint &rhs) {
return !(lhs == rhs);
}
private:
unsigned int _v = 0;
static constexpr unsigned int umod() {
return m;
}
};
using modint998244353 = static_modint<998244353>;
using modint1000000007 = static_modint<1000000007>;
} // namespace ebi
#line 2 "convolution/ntt.hpp"
#line 4 "convolution/ntt.hpp"
#include <array>
#line 8 "convolution/ntt.hpp"
#line 2 "math/internal_math.hpp"
#line 4 "math/internal_math.hpp"
namespace ebi {
namespace internal {
constexpr int primitive_root_constexpr(int m) {
if (m == 2) return 1;
if (m == 167772161) return 3;
if (m == 469762049) return 3;
if (m == 754974721) return 11;
if (m == 998244353) return 3;
if (m == 880803841) return 26;
if (m == 924844033) return 5;
return -1;
}
template <int m> constexpr int primitive_root = primitive_root_constexpr(m);
} // namespace internal
} // namespace ebi
#line 11 "convolution/ntt.hpp"
namespace ebi {
namespace internal {
template <Modint mint, int g = internal::primitive_root<mint::mod()>>
struct ntt_info {
static constexpr int rank2 =
std::countr_zero((unsigned int)(mint::mod() - 1));
std::array<mint, rank2 + 1> root, inv_root;
ntt_info() {
root[rank2] = mint(g).pow((mint::mod() - 1) >> rank2);
inv_root[rank2] = root[rank2].inv();
for (int i = rank2 - 1; i >= 0; i--) {
root[i] = root[i + 1] * root[i + 1];
inv_root[i] = inv_root[i + 1] * inv_root[i + 1];
}
}
};
template <Modint mint> void butterfly(std::vector<mint>& a) {
static const ntt_info<mint> info;
int n = int(a.size());
int bit_size = std::countr_zero(a.size());
assert(n == (int)std::bit_ceil(a.size()));
// bit reverse
for (int i = 0, j = 1; j < n - 1; j++) {
for (int k = n >> 1; k > (i ^= k); k >>= 1)
;
if (j < i) {
std::swap(a[i], a[j]);
}
}
for (int bit = 0; bit < bit_size; bit++) {
for (int i = 0; i < n / (1 << (bit + 1)); i++) {
mint zeta1 = 1;
mint zeta2 = info.root[1];
for (int j = 0; j < (1 << bit); j++) {
int idx = i * (1 << (bit + 1)) + j;
int jdx = idx + (1 << bit);
mint p1 = a[idx];
mint p2 = a[jdx];
a[idx] = p1 + zeta1 * p2;
a[jdx] = p1 + zeta2 * p2;
zeta1 *= info.root[bit + 1];
zeta2 *= info.root[bit + 1];
}
}
}
}
template <Modint mint> void butterfly_inv(std::vector<mint>& a) {
static const ntt_info<mint> info;
int n = int(a.size());
int bit_size = std::countr_zero(a.size());
assert(n == (int)std::bit_ceil(a.size()));
// bit reverse
for (int i = 0, j = 1; j < n - 1; j++) {
for (int k = n >> 1; k > (i ^= k); k >>= 1)
;
if (j < i) {
std::swap(a[i], a[j]);
}
}
for (int bit = 0; bit < bit_size; bit++) {
for (int i = 0; i < n / (1 << (bit + 1)); i++) {
mint zeta1 = 1;
mint zeta2 = info.inv_root[1];
for (int j = 0; j < (1 << bit); j++) {
int idx = i * (1 << (bit + 1)) + j;
int jdx = idx + (1 << bit);
mint p1 = a[idx];
mint p2 = a[jdx];
a[idx] = p1 + zeta1 * p2;
a[jdx] = p1 + zeta2 * p2;
zeta1 *= info.inv_root[bit + 1];
zeta2 *= info.inv_root[bit + 1];
}
}
}
mint inv_n = mint(n).inv();
for (int i = 0; i < n; i++) {
a[i] *= inv_n;
}
}
} // namespace internal
template <Modint mint>
std::vector<mint> convolution_naive(const std::vector<mint>& f,
const std::vector<mint>& g) {
if (f.empty() || g.empty()) return {};
int n = int(f.size()), m = int(g.size());
std::vector<mint> c(n + m - 1);
if (n < m) {
for (int j = 0; j < m; j++) {
for (int i = 0; i < n; i++) {
c[i + j] += f[i] * g[j];
}
}
} else {
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
c[i + j] += f[i] * g[j];
}
}
}
return c;
}
template <Modint mint>
std::vector<mint> convolution(const std::vector<mint>& f,
const std::vector<mint>& g) {
if (f.empty() || g.empty()) return {};
if (std::min(f.size(), g.size()) < 60) return convolution_naive(f, g);
int n = std::bit_ceil(f.size() + g.size() - 1);
std::vector<mint> a(n), b(n);
std::copy(f.begin(), f.end(), a.begin());
std::copy(g.begin(), g.end(), b.begin());
internal::butterfly(a);
internal::butterfly(b);
for (int i = 0; i < n; i++) {
a[i] *= b[i];
}
internal::butterfly_inv(a);
a.resize(f.size() + g.size() - 1);
return a;
}
} // namespace ebi
#line 2 "math/binomial.hpp"
#line 8 "math/binomial.hpp"
#line 10 "math/binomial.hpp"
namespace ebi {
template <Modint mint> struct Binomial {
private:
static void extend(int len = -1) {
int sz = (int)fact.size();
if (len < 0)
len = 2 * sz;
else
len = std::max(2 * sz, (int)std::bit_ceil(std::uint32_t(len)));
len = std::min(len, mint::mod());
assert(sz <= len);
fact.resize(len);
inv_fact.resize(len);
for (int i : std::views::iota(sz, len)) {
fact[i] = fact[i - 1] * i;
}
inv_fact[len - 1] = fact[len - 1].inv();
for (int i : std::views::iota(sz, len) | std::views::reverse) {
inv_fact[i - 1] = inv_fact[i] * i;
}
}
public:
Binomial() = default;
Binomial(int n) {
extend(n + 1);
}
static mint f(int n) {
if (n >= (int)fact.size()) [[unlikely]] {
extend(n + 1);
}
return fact[n];
}
static mint inv_f(int n) {
if (n >= (int)fact.size()) [[unlikely]] {
extend(n + 1);
}
return inv_fact[n];
}
static mint c(int n, int r) {
if (r < 0 || n < r) return 0;
return f(n) * inv_f(r) * inv_f(n - r);
}
static mint p(int n, int r) {
if (r < 0 || n < r) return 0;
return f(n) * inv_f(n - r);
}
static mint inv(int n) {
return inv_f(n) * f(n - 1);
}
static void reserve(int n) {
extend(n + 1);
}
private:
static std::vector<mint> fact, inv_fact;
};
template <Modint mint>
std::vector<mint> Binomial<mint>::fact = std::vector<mint>(2, 1);
template <Modint mint>
std::vector<mint> Binomial<mint>::inv_fact = std::vector<mint>(2, 1);
} // namespace ebi
#line 6 "a.cpp"
namespace ebi {
using mint = modint998244353;
void main_() {
int n;
i64 c;
std::cin >> n >> c;
c -= i64(1) << (n-1);
if(c < 0) {
std::cout << "0\n";
return;
}
int k = 0;
std::vector<mint> p = {1};
while(c > 0) {
if(k < n) {
std::vector<mint> f(k + 3,0);
rep(i,0,k+3) {
f[i] = Binomial<mint>::c(k+2, i);
}
p = convolution(p, f);
}
else {
std::vector<mint> f(n + 2, 0);
rep(i,0,n+2) {
f[i] = Binomial<mint>::c(n+1, i);
}
p = convolution(p, f);
}
std::vector<mint> nxt;
for(int i = c % 2; i < (int)p.size(); i += 2) {
nxt.emplace_back(p[i]);
}
std::swap(p, nxt);
k++;
c /= 2;
}
std::cout << p[0] << '\n';
}
} // namespace ebi
int main() {
ebi::fast_io();
int t = 1;
// std::cin >> t;
while (t--) {
ebi::main_();
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3632kb
input:
1 5
output:
5
result:
ok answer is '5'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
3 6
output:
4
result:
ok answer is '4'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
15 179
output:
0
result:
ok answer is '0'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
35 1234567887654321
output:
576695683
result:
ok answer is '576695683'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
45 228228228
output:
0
result:
ok answer is '0'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3800kb
input:
60 576460752303423487
output:
0
result:
ok answer is '0'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3488kb
input:
60 576460752303423488
output:
1
result:
ok answer is '1'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
1 1000000000000000000
output:
716070898
result:
ok answer is '716070898'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3536kb
input:
1 1
output:
1
result:
ok answer is '1'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3844kb
input:
15 1
output:
0
result:
ok answer is '0'
Test #11:
score: 0
Accepted
time: 0ms
memory: 3760kb
input:
1 964573170374708959
output:
695628865
result:
ok answer is '695628865'
Test #12:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
2 336
output:
28224
result:
ok answer is '28224'
Test #13:
score: 0
Accepted
time: 0ms
memory: 3540kb
input:
5 463
output:
172916212
result:
ok answer is '172916212'
Test #14:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
7 75427
output:
523581579
result:
ok answer is '523581579'
Test #15:
score: 0
Accepted
time: 0ms
memory: 3536kb
input:
10 28166
output:
145818175
result:
ok answer is '145818175'
Test #16:
score: 0
Accepted
time: 0ms
memory: 3476kb
input:
12 77890
output:
724302124
result:
ok answer is '724302124'
Test #17:
score: 0
Accepted
time: 0ms
memory: 3544kb
input:
3 401245
output:
68076875
result:
ok answer is '68076875'
Test #18:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
8 511955
output:
109524351
result:
ok answer is '109524351'
Test #19:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
15 484969
output:
99426993
result:
ok answer is '99426993'
Test #20:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
30 779369
output:
0
result:
ok answer is '0'
Test #21:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
17 638679755
output:
132031375
result:
ok answer is '132031375'
Test #22:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
25 669522429
output:
896585516
result:
ok answer is '896585516'
Test #23:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
29 748278478
output:
563047844
result:
ok answer is '563047844'
Test #24:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
33 642978862039931
output:
550967529
result:
ok answer is '550967529'
Test #25:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
38 218051542638139
output:
29411033
result:
ok answer is '29411033'
Test #26:
score: 0
Accepted
time: 0ms
memory: 3768kb
input:
44 188775063557057
output:
185410072
result:
ok answer is '185410072'
Test #27:
score: 0
Accepted
time: 0ms
memory: 3792kb
input:
48 4677253159871213
output:
863467586
result:
ok answer is '863467586'
Test #28:
score: 0
Accepted
time: 0ms
memory: 3540kb
input:
22 854279883518523144
output:
916505804
result:
ok answer is '916505804'
Test #29:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
38 730620861826239715
output:
433138392
result:
ok answer is '433138392'
Test #30:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
54 435826341367976434
output:
237455633
result:
ok answer is '237455633'
Test #31:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
55 536518888651224157
output:
665085880
result:
ok answer is '665085880'
Test #32:
score: 0
Accepted
time: 0ms
memory: 3572kb
input:
56 413839394784728775
output:
647247529
result:
ok answer is '647247529'
Test #33:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
57 514531937773009201
output:
425329246
result:
ok answer is '425329246'
Test #34:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
58 391852448201481116
output:
522300883
result:
ok answer is '522300883'
Test #35:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
59 492544995484728838
output:
937899244
result:
ok answer is '937899244'
Test #36:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
60 693597573066212298
output:
490610488
result:
ok answer is '490610488'
Test #37:
score: 0
Accepted
time: 0ms
memory: 3544kb
input:
60 1000000000000000000
output:
13328531
result:
ok answer is '13328531'
Extra Test:
score: 0
Extra Test Passed