QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#729105 | #9572. Bingo | ucup-team5657# | RE | 0ms | 12788kb | C++20 | 2.8kb | 2024-11-09 16:29:58 | 2024-11-09 16:30:06 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define _rep(i_,a_,b_) for(int i_ = (a_); i_ <= (b_); ++i_)
#define mid ((L+R) >> 1)
#define multiCase() int testCnt = in(); _rep(curCase,1,testCnt)
#ifdef ONLINE_JUDGE
#define debug(...) 0
#else
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#endif
using ll = long long;
using pii = pair<int,int>;
int in(void) { int x; scanf("%d", &x); return x; } ll inl(void) { ll x; scanf("%lld", &x); return x; }
void out(int x) { printf("%d ", x); } void outln(int x) { printf("%d\n", x); }
void out(ll x) { printf("%lld ", x); } void outln(ll x) { printf("%lld\n", x); }
template<typename T> void chkmax(T &a, const T &b) { a = max(a, b); }
template<typename T> void chkmin(T &a, const T &b) { a = min(a, b); }
const int kN = 205000, p = 998244353, G = 3;
int a[kN], fac[kN], iv[kN], ifac[kN], ans[kN];
int C(int n, int m) {
if(n < m) return 0;
return 1ll * fac[n] * ifac[m] % p * ifac[n - m] % p;
}
int fpm(int a, int b) {
int r = 1;
for(;b;b >>= 1, a = 1ll * a * a % p) if(b & 1) r = 1ll * r * a % p;
return r;
}
int f[1 << 21], g[1 << 21], h[1 << 21];
int r[1 << 21], l, L;
void NTT(int *A, int n) {
_rep(i,0,n - 1) if(i < r[i]) swap(A[i], A[r[i]]);
for(int i = 1; i < n; i <<= 1) {
int W = fpm(G, (p - 1) / i / 2);
for(int j = 0; j < n; j += i << 1) {
int w = 1;
_rep(k,0,i - 1) {
int x = (A[j + k] + 1ll * w * A[j + k + i]) % p,
y = (A[j + k] - 1ll * w * A[j + k + i] % p + p) % p;
A[j + k] = x, A[j + k + i] = y;
w = 1ll * w * W % p;
}
}
}
}
int main() {
fac[0] = ifac[0] = 1;
_rep(i,1,200000) fac[i] = 1ll * fac[i - 1] * i % p;
iv[1] = 1; _rep(i,2,200000) iv[i] = 1ll * iv[p % i] * (p - p / i) % p;
_rep(i,1,200000) ifac[i] = 1ll * ifac[i - 1] * iv[i] % p;
multiCase() {
int n = in(), m = in();
_rep(i,1,n * m) a[i] = in();
sort(a + 1, a + n * m + 1); int N = n * m, v = a[N];
_rep(i,0,N) f[i] = g[i] = 0;
_rep(i,0,n) _rep(j,0,m) if(i + j) {
int tot = i * m + j * n - i * j;
int g = 1ll * C(n, i) * C(m, j) % p * fac[tot] % p * fac[n * m - tot] % p;
if((i + j) % 2 == 0) g = (p - g);
f[tot] = (f[tot] + g) % p;
}
_rep(i,0,N) f[i] = 1ll * f[i] * ifac[i] % p, g[i] = ifac[i];
l = 0; while((1 << l) <= N * 2) ++l; L = 1 << l;
_rep(i,N + 1,L - 1) f[i] = g[i] = 0;
_rep(i,1,L - 1) r[i] = (r[i >> 1] >> 1) | ((i & 1) << (l - 1));
NTT(f, L), NTT(g, L);
_rep(i,0,L - 1) f[i] = 1ll * f[i] * g[i] % p;
NTT(f, L); reverse(f + 1, f + L); int iv = fpm(L, p - 2);
_rep(i,0,L - 1) f[i] = 1ll * f[i] * iv % p * fac[i] % p;
int res = 0, cnt = 0;
_rep(k,1,v) {
while(cnt + 1 <= n * m && a[cnt + 1] <= k) ++cnt;
ans[k] = f[cnt];
}
// int ans = 0;
_rep(k,1,v) res = (res + 1ll * k * (ans[k] - ans[k - 1] + p)) % p;
outln(res);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 12788kb
input:
4 2 2 1 3 2 4 3 1 10 10 10 1 3 20 10 30 3 4 1 1 4 5 1 4 1 9 1 9 8 10
output:
56 60 60 855346687
result:
ok 4 number(s): "56 60 60 855346687"
Test #2:
score: -100
Runtime Error
input:
1 2 2 0 0 998244352 998244352