QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#613965 | #9436. Some Sum of Subset | ucup-team2010# | WA | 1ms | 3828kb | C++23 | 6.2kb | 2024-10-05 15:12:12 | 2024-10-05 15:16:28 |
Judging History
answer
#include<bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;
using ll = long long;
#define LNF 0x3f3f3f3f3f3f3f3f
#define W(...) cerr<<"LINE:" << __LINE__ << " "; debug(#__VA_ARGS__, __VA_ARGS__)
void debug(const char* names) {cerr << endl;} template<typename T, typename... Args>void debug(const char* names, T value, Args... args) {const char* comma = strchr(names, ','); if (comma) {cerr.write(names, comma - names) << "=" << value << ", "; debug(comma + 1, args...);} else {cerr << names << " = " << value << endl; }}
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T, class... U>void chmax(T &a, const U &... b) {for (const auto& val : {b...})if (a < val) {a = val;}}
template<class T, class... U>void chmin(T &a, const U &... b) {for (const auto& val : {b...})if (a > val) {a = val;}}
#define pb push_back
template<class T>
constexpr T power(T a, ll b) {
T res = 1;
for (; b; b /= 2, a *= a) {
if (b % 2) {
res *= a;
}
}
return res;
}
template<int P>
struct MInt {
int x;
constexpr MInt() : x{} {}
constexpr MInt(ll x) : x{norm(x % P)} {}
constexpr int norm(int x) const {
if (x < 0) {
x += P;
}
if (x >= P) {
x -= P;
}
return x;
}
constexpr int val() const {
return x;
}
explicit constexpr operator int() const {
return x;
}
constexpr MInt operator-() const {
MInt res;
res.x = norm(P - x);
return res;
}
constexpr MInt inv() const {
assert(x != 0);
return power(*this, P - 2);
}
constexpr MInt &operator*=(MInt rhs) {
x = 1LL * x * rhs.x % P;
return *this;
}
constexpr MInt &operator+=(MInt rhs) {
x = norm(x + rhs.x);
return *this;
}
constexpr MInt &operator-=(MInt rhs) {
x = norm(x - rhs.x);
return *this;
}
constexpr MInt &operator/=(MInt rhs) {
return *this *= rhs.inv();
}
friend constexpr MInt operator*(MInt lhs, MInt rhs) {
MInt res = lhs;
res *= rhs;
return res;
}
friend constexpr MInt operator+(MInt lhs, MInt rhs) {
MInt res = lhs;
res += rhs;
return res;
}
friend constexpr MInt operator-(MInt lhs, MInt rhs) {
MInt res = lhs;
res -= rhs;
return res;
}
friend constexpr MInt operator/(MInt lhs, MInt rhs) {
MInt res = lhs;
res /= rhs;
return res;
}
friend constexpr std::istream &operator>>(std::istream &is, MInt &a) {
ll v;
is >> v;
a = MInt(v);
return is;
}
friend constexpr std::ostream &operator<<(std::ostream &os, const MInt &a) {
return os << a.val();
}
friend constexpr bool operator==(MInt lhs, MInt rhs) {
return lhs.val() == rhs.val();
}
friend constexpr bool operator!=(MInt lhs, MInt rhs) {
return lhs.val() != rhs.val();
}
};
template<int V, int P>
constexpr MInt<P> CInv = MInt<P>(V).inv();
constexpr int P = 998244353;
// constexpr int P = 1e9+7;
using Z = MInt<P>;
struct Comb {
int n;
std::vector<Z> _fac;
std::vector<Z> _invfac;
std::vector<Z> _inv;
Comb() : n{0}, _fac{1}, _invfac{1}, _inv{0} {}
Comb(int n) : Comb() {
init(n);
}
void init(int m) {
if (m <= n) return;
_fac.resize(m + 1);
_invfac.resize(m + 1);
_inv.resize(m + 1);
for (int i = n + 1; i <= m; i++) {
_fac[i] = _fac[i - 1] * i;
}
_invfac[m] = _fac[m].inv();
for (int i = m; i > n; i--) {
_invfac[i - 1] = _invfac[i] * i;
_inv[i] = _invfac[i] * _fac[i - 1];
}
n = m;
}
Z fac(int m) {
if (m > n) init(2 * m);
return _fac[m];
}
Z invfac(int m) {
if (m > n) init(2 * m);
return _invfac[m];
}
Z inv(int m) {
if (m > n) init(2 * m);
return _inv[m];
}
Z binom(int n, int m) {
if (n < m || m < 0) return 0;
return fac(n) * invfac(m) * invfac(n - m);
}
} comb;
struct Inversion {
static constexpr int B = (1 << 10), T = (1 << 20);
std::array < int, T + 1 > f, p;
std::array < int, T * 3 + 3 > buf;
int *I = buf.begin() + T;
Inversion() {
for (int i = 1; i <= B; i++) {
int s = 0, d = (i << 10);
for (int j = 1; j <= T; j++) {
if ((s += d) >= P) s -= P;
if (s <= T) {
if (!f[j]) f[j] = i, p[j] = s;
}
else if (s >= P - T) {
if (!f[j]) f[j] = i, p[j] = s - P;
}
else {
int t = (P - T - s - 1) / d;
s += t * d, j += t;
}
}
}
I[1] = f[0] = 1;
for (int i = 2; i <= (T << 1); i++)
I[i] = 1ll * (P - P / i) * I[P % i] % P;
for (int i = -1; i >= -T; i--)
I[i] = P - I[-i];
}
Z inv(int x) {
return Z(1) * I[p[x >> 10] + (x & 1023) * f[x >> 10]] * f[x >> 10];
}
};
Z ans[3005];
Z dp[3005];
void solve(void) {
ll n, m;
cin >> n >> m;
std::vector<ll> v(n + 1);
for (int i = 1; i <= n; i++) {
cin >> v[i];
}
sort(v.begin() + 1, v.end(), greater<>());
dp[0] = 1;
for (int i = 1; i <= n; i++) {
Z sum = 0;
for (int s = m; s >= 0; s--) {
if (s + v[i] >= m) {
sum += dp[s];
} else {
dp[s + v[i]] += dp[s];
}
}
for (int k = 0; k <= n - i; k++) {
ans[k] += (sum * comb.binom(n - i, k));
}
}
for (int i = n - 1; i >= 0; i--) {
ans[i] += ans[i + 1];
}
for (int i = 0; i <= n; i++) {
cout << ans[i] << "\n";
}
cout << 0;
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int t = 1;
// cin>>t;
while (t--)
solve();
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3828kb
input:
4 7 3 1 5 2
output:
6 4 1 0 0 0
result:
wrong answer Participant output contains extra tokens