QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#252343 | #7754. Rolling For Days | ucup-team1453# | WA | 0ms | 5836kb | C++11 | 2.3kb | 2023-11-15 18:33:23 | 2023-11-15 18:33:24 |
Judging History
answer
#include<bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); ++i)
#define R(i, j, k) for(int i = (j); i >= (k); --i)
#define ll long long
#define vi vector <int>
#define sz(a) ((int) (a).size())
#define me(f, x) memset(f, x, sizeof(f))
#define uint unsig7ned int
#define ull unsigned long long
#define i128 __int128
using namespace std;
const int N = 5000, mod = 998244353;
int qpow(int x, int y = mod - 2) {
int res = 1;
for(; y; x = (ll) x * x % mod, y >>= 1) if(y & 1) res = (ll) res * x % mod;
return res;
}
int fac[N], ifac[N], inv[N];
void init(int x) {
fac[0] = ifac[0] = inv[1] = 1;
L(i, 2, x) inv[i] = (ll) (mod - mod / i) * inv[mod % i] % mod;
L(i, 1, x) fac[i] = (ll) fac[i - 1] * i % mod, ifac[i] = (ll) ifac[i - 1] * inv[i] % mod;
}
int C(int x, int y) {
return x < y || y < 0 ? 0 : (ll) fac[x] * ifac[y] % mod * ifac[x - y] % mod;
}
inline int sgn(int x) {
return (x & 1) ? mod - 1 : 1;
}
int n, m;
int a[N];
int b[N];
int f[N][N];
int g[N][N];
int main() {
ios :: sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n >> m;
init(n + 1);
L(i, 0, m - 1) {
cin >> a[i];
}
int sumc = 0;
L(i, 0, m - 1) {
cin >> b[i];
sumc += b[i];
}
int mul = 1;
L(i, 0, sumc - 1) {
mul = (ll) mul * inv[n - i] % mod;
}
L(i, 0, m - 1) {
L(j, 0, b[i] - 1) {
mul = (ll) mul * (a[i] - j) % mod;
}
}
f[0][0] = mul;
g[0][0] = 0;
L(sub, 0, (1 << m) - 1) {
int sumb = 0, qwq = 0;
L(i, 0, m - 1)
if(sub >> i & 1)
sumb += b[i], qwq += a[i] - b[i];
L(i, sumb, sumc - 1) {
int kn = n - i;
int prob = (ll) kn * inv[kn - qwq] % mod;
int sg = (ll) prob * prob % mod;
(f[sub][i + 1] += (ll) f[sub][i] * prob % mod) %= mod;
(g[sub][i + 1] += (ll) g[sub][i] * prob % mod) %= mod;
(g[sub][i + 1] += (ll) f[sub][i] * sg % mod) %= mod;
L(p, 0, m - 1) if(!(sub >> p & 1)) {
int c = C(i - sumb, b[p] - 1);
(f[sub + (1 << p)][i + 1] += (ll) c * f[sub][i] % mod * prob % mod) %= mod;
(g[sub + (1 << p)][i + 1] += (ll) c * g[sub][i] % mod * prob % mod) %= mod;
(g[sub + (1 << p)][i + 1] += (ll) c * f[sub][i] % mod * sg % mod) %= mod;
}
}
}
cout << g[(1 << m) - 1][sumc] << '\n';
return 0;
}
/*
3 2
2 1
1 1
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5608kb
input:
2 2 1 1 1 1
output:
2
result:
ok answer is '2'
Test #2:
score: 0
Accepted
time: 0ms
memory: 5632kb
input:
4 2 2 2 2 1
output:
582309210
result:
ok answer is '582309210'
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 5836kb
input:
5 5 1 1 1 1 1 0 0 0 0 1
output:
0
result:
wrong answer expected '5', found '0'