QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#729132#9572. Bingoucup-team5657#WA 75ms11108kbC++202.7kb2024-11-09 16:32:342024-11-09 16:32:36

Judging History

你现在查看的是最新测评结果

  • [2024-11-09 16:32:36]
  • 评测
  • 测评结果:WA
  • 用时:75ms
  • 内存:11108kb
  • [2024-11-09 16:32:34]
  • 提交

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; a[N + 1] = 0;
		_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, lst = 0;
		_rep(k,1,N) if(a[k] != a[k + 1]) {
			res = (res + 1ll * a[k] * (f[k] - lst)) % p;
			lst = f[k];
		}
		outln(res);
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 4ms
memory: 10884kb

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: 0
Accepted
time: 0ms
memory: 11108kb

input:

1
2 2
0 0 998244352 998244352

output:

998244345

result:

ok 1 number(s): "998244345"

Test #3:

score: -100
Wrong Answer
time: 75ms
memory: 10784kb

input:

900
1 1
810487041
1 2
569006976 247513378
1 3
424212910 256484544 661426830
1 4
701056586 563296095 702740883 723333858
1 5
725786515 738465053 821758167 170452477 34260723
1 6
204184507 619884535 208921865 898995024 768400582 369477346
1 7
225635227 321139203 724076812 439129905 405005469 369864252...

output:

810487041
495026756
540662911
541929691
118309348
270925149
575366228
709974238
761347712
304011276
14811741
366145628
638305530
240546928
484276475
603344008
926633861
161768904
239961447
329781933
315752584
578075668
259941994
600147169
402221164
890998500
154285994
181862417
47930994
273729619
64...

result:

wrong answer 38th numbers differ - expected: '827542334', found: '-170702019'