QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#269757 | #7754. Rolling For Days | FISHER_ | WA | 1ms | 5936kb | C++20 | 2.4kb | 2023-11-29 22:44:00 | 2023-11-29 22:44:00 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
inline int Mod(int x) { return x + ((x >> 31) & mod); }
inline int add(int x, int y) { return Mod(x + y - mod); }
inline int sub(int x, int y) { return Mod(x - y); }
inline int mul(int x, int y) { return 1ll * x * y % mod; }
inline int sqr(int x) { return 1ll * x * x % mod; }
int qpow(int a, int b) {
if (!b) return 1;
int t = qpow(a, b >> 1);
t = mul(t, t);
if (b & 1) return mul(t, a);
return t;
}
const int maxn = 1000, maxm = 12;
int fac[maxn + 5], ifac[maxn + 5];
void init(int n) {
fac[0] = 1;
for (int i = 1; i <= n; i++) fac[i] = mul(fac[i - 1], i);
ifac[n] = qpow(fac[n], mod - 2);
for (int i = n - 1; ~i; i--) ifac[i] = mul(ifac[i + 1], i + 1);
}
inline int C(int m, int n) { return mul(fac[m], mul(ifac[m - n], ifac[n])); }
int a[maxm + 5], b[maxm + 5];
int sa[1 << maxm], sb[1 << maxm];
int f[maxn + 5][1 << maxm], g[maxn + 5][1 << maxm];
int sf[maxn + 5][1 << maxm], sg[maxn + 5][1 << maxm], sg2[maxn + 5][1 << maxm];
int p[maxn + 5][maxn + 5];
inline void upd(int& x, int y) { x = add(x, y); }
int main() {
int n, m, N = 0;
scanf("%d%d", &n, &m);
for (int i = 0; i < m; i++) scanf("%d", &a[i]);
for (int i = 0; i < m; i++) scanf("%d", &b[i]), N += b[i];
int S = 1 << m;
for (int s = 0; s < S; s++) {
sa[s] = n;
for (int i = 0; i < m; i++)
if ((s >> i) & 1) sa[s] -= a[i], sb[s] += b[i];
}
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) p[i][j] = add(p[i][j - 1], mul(n - j + 1, qpow(i - j + 1, mod - 2)));
init(n);
sg[0][0] = ifac[n];
for (int i = 1; i <= N; i++)
for (int s = 0; s < S; s++) {
if (i < sb[s]) continue;
for (int x = 0; x < m; x++)
if ((s >> x) & 1) {
int fs = s ^ (1 << x);
upd(f[i][s], mul(add(sub(mul(sg[i - 1][fs], p[sa[fs] + sb[fs]][i]), sg2[i - 1][fs]), sf[i - 1][fs]), mul(C(i - 1 - sb[fs], b[x] - 1), fac[sa[fs] - i + sb[fs]])));
upd(g[i][s], mul(sg[i - 1][fs], mul(C(i - 1 - sb[fs], b[x] - 1), fac[sa[fs] - i + sb[fs]])));
}
sf[i][s] = add(sf[i - 1][s], mul(f[i][s], ifac[sa[s] - i + sb[s]]));
sg[i][s] = add(sg[i - 1][s], mul(g[i][s], ifac[sa[s] - i + sb[s]]));
sg2[i][s] = add(sg2[i - 1][s], mul(g[i][s], mul(ifac[sa[s] - i + sb[s]], p[sa[s] + sb[s]][i])));
}
int ans = f[N][S - 1];
for (int i = 0; i < m; i++) ans = mul(ans, mul(fac[a[i]], ifac[a[i] - b[i]]));
printf("%d", ans);
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5628kb
input:
2 2 1 1 1 1
output:
2
result:
ok answer is '2'
Test #2:
score: 0
Accepted
time: 1ms
memory: 5936kb
input:
4 2 2 2 2 1
output:
582309210
result:
ok answer is '582309210'
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 5628kb
input:
5 5 1 1 1 1 1 0 0 0 0 1
output:
0
result:
wrong answer expected '5', found '0'