QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#708029 | #6328. Many Products | ucup-team3691 | WA | 626ms | 11836kb | C++14 | 5.1kb | 2024-11-03 18:57:36 | 2024-11-03 18:57:37 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
using ll = long long;
using ull = unsigned long long;
string to_string(const string &s) {
return '"' + s + '"';
}
string to_string(bool b) {
return b ? "true" : "false";
}
template <typename A, typename B>
string to_string(const pair<A, B> &p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename T>
string to_string(const T &v) {
string s = "{";
bool first = true;
for (const auto &it : v) {
if (!first)
s += ", ";
else
first = false;
s += to_string(it);
}
return s += "}";
}
void debug_out() {
cerr << endl;
}
template <typename T, typename... Args>
void debug_out(const T &first, const Args&... rest) {
cerr << to_string(first) << " ";
debug_out(rest...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
auto startTime = high_resolution_clock::now();
int get_time() {
auto stopTime = chrono::high_resolution_clock::now();
auto duration = duration_cast<milliseconds>(stopTime - startTime);
return duration.count(); // in ms
}
const int MOD = 998244353;
constexpr int lgpow(int x, int p) {
int aux = x, ans = 1;
for (int i = 1; i <= p; i <<= 1) {
if (i & p)
ans = 1ll * ans * aux % MOD;
aux = 1ll * aux * aux % MOD;
}
return ans;
}
constexpr int invmod(int x) {
return lgpow(x, MOD - 2);
}
namespace NTT {
vector<int> ntt( vector<int> &a, int g ) {
int n = a.size();
int lg = log2(n);
for ( int i = 0; i < n; ++i ) {
int j = 0;
for ( int b = 0; b < lg; ++b ) {
j += ( ( ( i >> b ) & 1 ) << ( lg - b - 1 ) );
}
if ( j < i ) {
swap(a[i], a[j]);
}
}
for ( int l = 2; l <= n; l <<= 1 ) {
int p = lgpow(g, n / l);
for ( int b = 0; b < n; b += l ) {
for ( int i = 0, t = 1; i < l / 2; ++i, t = (1ll * t * p) % MOD ) {
int x = a[b + i], y = 1ll * a[b + i + l / 2] * t % MOD;
a[b + i] = (x + y) % MOD;
a[b + i + l / 2] = (1ll * MOD + x - y) % MOD;
}
}
}
return a;
}
vector<int> mul( vector<int> a, vector<int> b ) {
int n = a.size() + b.size() - 1;
int p2 = 1;
while ( p2 < n ) {
p2 *= 2;
}
n = p2;
while ( a.size() < n ) {
a.push_back(0);
}
while ( b.size() < n ) {
b.push_back(0);
}
auto ra = ntt(a, lgpow(3, MOD / n));
auto rb = ntt(b, lgpow(3, MOD / n));
for( int i = 0; i < ra.size(); ++i ) {
ra[i] = 1ll * ra[i] * rb[i] % MOD;
}
ra = ntt(ra, lgpow(lgpow(3, MOD - 2), MOD / n));
int inv = lgpow(ra.size(), MOD - 2);
for( int i = 0; i < ra.size(); ++i ) {
ra[i] = 1ll * ra[i] * inv % MOD;
}
while ( !ra.back() )
ra.pop_back();
return ra;
}
};
namespace comb {
vector<int> fact, ifact;
void init(int n) {
fact.resize(n + 1);
ifact.resize(n + 1);
fact[0] = 1;
for (int i = 1; i <= n; ++i) {
fact[i] = 1LL * fact[i - 1] * i % MOD;
}
ifact[n] = invmod(fact[n]);
for (int i = n - 1; i >= 0; --i) {
ifact[i] = 1LL * ifact[i + 1] * (i + 1) % MOD;
}
}
int comb(int n, int k) {
return 1LL * fact[n] * ifact[k] % MOD * ifact[n - k] % MOD;
}
}
vector<int> divide(int st, int dr, vector<int> &a) {
if (st == dr) {
return {a[st], 1};
}
int mij = (st + dr) / 2;
auto l = divide(st, mij, a);
auto r = divide(mij + 1, dr, a);
return NTT::mul(l, r);
}
void solve() {
int n;
ll m;
cin >> n >> m;
vector<int> a(n + 1);
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
if (m == 1) {
int p = 1;
for (int i = 1; i <= n; ++i) {
p = 1LL * p * (a[i] + 1) % MOD;
}
cout << p << "\n";
return;
}
auto b = divide(1, n, a);
vector<pair<int, int>> p;
for (int i = 2; 1LL * i * i <= m; ++i) {
int k = 0;
while (m % i == 0) {
m /= i;
++k;
}
if (k > 0)
p.push_back({i % MOD, k});
}
if (m > 1)
p.push_back({m % MOD, 1});
vector<int> ans = b;
comb::init(n + 50);
for (auto [x, y] : p) {
ans[0] = (ans[0] * comb::comb(y + n - 1, n - 1)) % MOD;
for (int k = 1; k < n; ++k) {
int c = 1;
int sum = 0;
for (int j = 0; j <= y; ++j) {
sum = (sum + 1LL * c % MOD * comb::comb(k + j - 1, k - 1) % MOD
* comb::comb(y - j + n - k - 1, n - k - 1)) % MOD;
c = 1LL * c * x % MOD;
}
ans[k] = 1LL * ans[k] * sum % MOD;
}
ans[n] = (ans[n] * 1LL * lgpow(x, y) % MOD * comb::comb(y + n - 1, n - 1) % MOD) % MOD;
}
int sum = 0;
for (auto it : ans)
sum = (sum + it) % MOD;
cout << sum << "\n";
}
int main() {
cin.tie(NULL);
ios_base::sync_with_stdio(false);
int t = 1;
// cin >> t;
while (t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3628kb
input:
2 3 0 1
output:
10
result:
ok 1 number(s): "10"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
5 1 0 1 2 3 4
output:
120
result:
ok 1 number(s): "120"
Test #3:
score: 0
Accepted
time: 2ms
memory: 3684kb
input:
10 314159265358 0 1 2 3 4 5 6 7 8 9
output:
658270849
result:
ok 1 number(s): "658270849"
Test #4:
score: -100
Wrong Answer
time: 626ms
memory: 11836kb
input:
200000 999999999989 823489320 406308599 710963770 183707427 192930969 941365774 318564299 391028855 945374838 651744270 515755727 220857626 599403217 214957584 335628890 771694833 40989299 34892948 630275822 869708185 432704750 924850167 707864789 232688853 406616372 529994171 782650336 979286144 65...
output:
794279207
result:
wrong answer 1st numbers differ - expected: '777405593', found: '794279207'