QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#283654 | #6328. Many Products | Misuki | WA | 397ms | 44504kb | C++20 | 7.7kb | 2023-12-15 01:12:06 | 2023-12-15 01:12:06 |
Judging History
answer
#pragma GCC optimize("O2")
#include <bits/extc++.h>
#include <algorithm>
#include <array>
#include <bit>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfenv>
#include <cfloat>
#include <chrono>
#include <cinttypes>
#include <climits>
#include <cmath>
#include <compare>
#include <complex>
#include <concepts>
#include <cstdarg>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <new>
#include <numbers>
#include <numeric>
#include <ostream>
#include <queue>
#include <random>
#include <ranges>
#include <set>
#include <span>
#include <sstream>
#include <stack>
#include <streambuf>
#include <string>
#include <tuple>
#include <type_traits>
#include <variant>
#define int ll
#define INT128_MAX (__int128)(((unsigned __int128) 1 << ((sizeof(__int128) * __CHAR_BIT__) - 1)) - 1)
#define INT128_MIN (-INT128_MAX - 1)
namespace R = std::ranges;
namespace V = std::views;
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
using tiii = tuple<int, int, int>;
using ldb = long double;
//#define double ldb
template<class T>
ostream& operator<<(ostream& os, const pair<T, T> pr) {
return os << pr.first << ' ' << pr.second;
}
template<class T, size_t N>
ostream& operator<<(ostream& os, const array<T, N> &arr) {
for(const T &X : arr)
os << X << ' ';
return os;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T> &vec) {
for(const T &X : vec)
os << X << ' ';
return os;
}
/**
* template name: MontgomeryModInt
* author: Misuki
* reference: https://github.com/NyaanNyaan/library/blob/master/modint/montgomery-modint.hpp#L10
* last update: 2023/11/30
* note: mod should be a prime less than 2^30.
*/
template<uint32_t mod>
struct MontgomeryModInt {
using mint = MontgomeryModInt;
using i32 = int32_t;
using u32 = uint32_t;
using u64 = uint64_t;
static constexpr u32 get_r() {
u32 res = 1, base = mod;
for(i32 i = 0; i < 31; i++)
res *= base, base *= base;
return -res;
}
static constexpr u32 get_mod() {
return mod;
}
static constexpr u32 n2 = -u64(mod) % mod; //2^64 % mod
static constexpr u32 r = get_r(); //-P^{-1} % 2^32
u32 a;
static u32 reduce(const u64 &b) {
return (b + u64(u32(b) * r) * mod) >> 32;
}
static u32 transform(const u64 &b) {
return reduce(u64(b) * n2);
}
MontgomeryModInt() : a(0) {}
MontgomeryModInt(const int64_t &b)
: a(transform(b % mod + mod)) {}
mint pow(u64 k) const {
mint res(1), base(*this);
while(k) {
if (k & 1)
res *= base;
base *= base, k >>= 1;
}
return res;
}
mint inverse() const { return (*this).pow(mod - 2); }
u32 get() const {
u32 res = reduce(a);
return res >= mod ? res - mod : res;
}
mint& operator+=(const mint &b) {
if (i32(a += b.a - 2 * mod) < 0) a += 2 * mod;
return *this;
}
mint& operator-=(const mint &b) {
if (i32(a -= b.a) < 0) a += 2 * mod;
return *this;
}
mint& operator*=(const mint &b) {
a = reduce(u64(a) * b.a);
return *this;
}
mint& operator/=(const mint &b) {
a = reduce(u64(a) * b.inverse().a);
return *this;
}
mint operator-() { return mint() - mint(*this); }
bool operator==(mint b) {
return (a >= mod ? a - mod : a) == (b.a >= mod ? b.a - mod : b.a);
}
bool operator!=(mint b) {
return (a >= mod ? a - mod : a) != (b.a >= mod ? b.a - mod : b.a);
}
friend mint operator+(mint a, mint b) { return a += b; }
friend mint operator-(mint a, mint b) { return a -= b; }
friend mint operator*(mint a, mint b) { return a *= b; }
friend mint operator/(mint a, mint b) { return a /= b; }
friend ostream& operator<<(ostream& os, const mint& b) {
return os << b.get();
}
friend istream& operator>>(istream& is, mint& b) {
int64_t val;
is >> val;
b = mint(val);
return is;
}
};
using mint = MontgomeryModInt<998244353>;
/**
* template name: comb
* author: Misuki
* last update: 2023/01/22
* note: remember to call init() before using it.
*/
const int MAX = 200001;
mint fac[MAX], facInv[MAX];
void init() {
fac[0] = 1;
for(int i = 1; i < MAX; i++)
fac[i] = fac[i - 1] * i;
facInv[MAX - 1] = 1 / fac[MAX - 1];
for(int i = MAX - 2; i >= 0; i--)
facInv[i] = facInv[i + 1] * (i + 1);
}
mint C(int a, int b) {
if (b < 0 or a < b)
return 0;
else
return fac[a] * facInv[b] * facInv[a - b];
}
/**
* template name: hashTable
* reference: https://codeforces.com/blog/entry/62393
* last update: 2022/12/03
* header: bit/extc++.h (or ext/pb_ds/assoc_container.hpp for CF)
*/
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
using namespace __gnu_pbds;
gp_hash_table<ll, int, custom_hash> toId;
const int pi = 40;
signed main() {
ios::sync_with_stdio(false), cin.tie(NULL);
init();
int n, m; cin >> n >> m;
vector<mint> a(n);
for(mint &x : a)
cin >> x;
vector<int> div;
for(int i = 1; i * i <= m; i++) {
if (m % i == 0) {
div.emplace_back(i);
if (i * i != m)
div.emplace_back(m / i);
}
}
R::sort(div);
vector<int> pf;
{
int tmp = m;
for(int i = 2; i * i <= m; i++) {
if (tmp % i == 0) {
pf.emplace_back(i);
while(tmp % i == 0)
tmp /= i;
}
}
if (tmp != 1)
pf.emplace_back(tmp);
}
for(int i = 0; i < ssize(div); i++)
toId[div[i]] = i;
vector<vector<int>> f(ssize(div));
for(int i = 0; int d : div) {
for(int p : pf) {
if (d % p == 0) {
f[i].emplace_back(0);
while(d % p == 0)
d /= p, f[i].back()++;
}
}
i++;
}
vector<vector<array<int, 2>>> trans(ssize(div));
for(int j = 0; j < ssize(div); j++)
for(int k = 1; k <= j; k++)
if (div[j] % div[k] == 0)
trans[j].push_back({toId[div[j] / div[k]], div[k] - 1});
vector dp(pi + 1, vector<mint>(ssize(div)));
dp[0][0] = 1;
for(int i = 1; i <= pi; i++)
for(int j = 0; j < ssize(div); j++)
for(auto [k, r] : trans[j])
dp[i][j] += dp[i - 1][k] * r;
vector<mint> dp2(pi + 1);
dp2[0] = 1;
for(int i = 0; i < n; i++) {
vector<mint> tmp(pi + 1);
for(int j = 0; j <= pi; j++)
tmp[j] = dp2[j] * (a[i] + 1);
for(int j = 1; j <= pi; j++)
tmp[j] += dp2[j - 1];
dp2.swap(tmp);
}
mint ans = 0;
for(int i = 0; i <= pi; i++) {
for(int j = 0; j < ssize(div); j++) {
mint tmp = 1;
for(int k : f[toId[m / div[j]]])
tmp *= C(n - i - 1 + k, k);
ans += dp[i][j] * dp2[i] * tmp;
}
}
cout << ans << '\n';
/*
cout << "div: " << div << '\n';
cout << "pf: " << pf << '\n';
cout << "f: " << f << '\n';
cout << "dp: \n";
for(auto v : dp)
cout << v << '\n';
cout << "dp2: " << dp2 << '\n';
for(auto [x, y] : toId)
cout << x << ' ' << y << '\n';
*/
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 5196kb
input:
2 3 0 1
output:
10
result:
ok 1 number(s): "10"
Test #2:
score: 0
Accepted
time: 3ms
memory: 5336kb
input:
5 1 0 1 2 3 4
output:
120
result:
ok 1 number(s): "120"
Test #3:
score: 0
Accepted
time: 6ms
memory: 5160kb
input:
10 314159265358 0 1 2 3 4 5 6 7 8 9
output:
658270849
result:
ok 1 number(s): "658270849"
Test #4:
score: 0
Accepted
time: 36ms
memory: 5428kb
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:
777405593
result:
ok 1 number(s): "777405593"
Test #5:
score: 0
Accepted
time: 32ms
memory: 5476kb
input:
199999 999999999331 969252353 737776924 108584656 914893031 394348303 484491127 481944452 120707790 396027156 912223841 673218447 285837840 782450963 144940963 892852383 782342131 655814479 1324532 794011279 219428289 470995270 489684781 347978895 102371386 546635675 585575402 940741300 644383693 67...
output:
573300948
result:
ok 1 number(s): "573300948"
Test #6:
score: 0
Accepted
time: 46ms
memory: 7064kb
input:
200000 742073813481 681694404 632869785 595996398 549654767 229574822 571126931 469341419 702184356 904366313 746328903 842820475 578092052 586236587 796973195 766841610 123554290 666934376 118830348 326368534 40766155 790927880 880528134 890721558 357539968 885997091 937508042 5345140 189162897 200...
output:
998002127
result:
ok 1 number(s): "998002127"
Test #7:
score: -100
Wrong Answer
time: 397ms
memory: 44504kb
input:
199999 963761198400 124206358 425059813 396286827 293468808 45861386 890748681 587148852 2565459 137729579 865441288 710978415 682768035 62610967 490442955 426217252 132942846 314800009 680954919 208583546 438814504 79283475 26876485 718279429 714019319 799517726 874565672 262935553 180792133 654326...
output:
105018862
result:
wrong answer 1st numbers differ - expected: '150795568', found: '105018862'