QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#297309#5829. 马戏团里你最忙FISHER_20 116ms29608kbC++142.0kb2024-01-04 10:23:202024-01-04 10:23:21

Judging History

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

  • [2024-01-04 10:23:21]
  • 评测
  • 测评结果:20
  • 用时:116ms
  • 内存:29608kb
  • [2024-01-04 10:23:20]
  • 提交

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; }
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 = 17;
int n, p, pp, K, x0;
int c[1 << maxn];
int f[105][1 << maxn], g[105][1 << maxn];
void fwtOr(int v[], int len, bool tp) {
	for (int i = 1; i < len; i <<= 1)
		for (int j = 0; j < len; j += i << 1)
			for (int k = 0; k < i; k++) {
				if (tp) v[i + j + k] = sub(v[i + j + k], v[j + k]);
				else v[i + j + k] = add(v[i + j + k], v[j + k]);
			}
}
void fwtAnd(int v[], int len, bool tp) {
	for (int i = 1; i < len; i <<= 1)
		for (int j = 0; j < len; j += i << 1)
			for (int k = 0; k < i; k++) {
				if (tp) v[j + k] = sub(v[j + k], v[i + j + k]);
				else v[j + k] = add(v[j + k], v[i + j + k]);
			}
}
int tra[1 << maxn], tro[1 << maxn];
int t1[1 << maxn], t2[1 << maxn];
void tr(const int fr[], int to[], int len) {
	memcpy(t1, fr, sizeof(t1));
	fwtOr(t1, len, 0);
	for (int s = 0; s < len; s++) to[s] = mul(mul(t1[s], tro[s]), p);
	fwtOr(to, len, 1);
	memcpy(t1, fr, sizeof(t1));
	fwtAnd(t1, len, 0);
	for (int s = 0; s < len; s++) t2[s] = mul(mul(t1[s], tra[s]), pp);
	fwtAnd(t2, len, 1);
	for (int s = 0; s < len; s++) to[s] = add(to[s], t2[s]);
}
int main() {
	scanf("%d%d%d%d", &n, &p, &K, &x0), pp = sub(1, p);
	int S = 1 << n;
	int inv = qpow(S, mod - 2);
	for (int s = 0; s < S; s++) {
		scanf("%d", &c[s]);
		tra[s] = tro[s] = inv;
	}
	fwtAnd(tra, S, 0), fwtOr(tro, S, 0);
	g[0][x0] = 1;
	for (int i = 1; i <= K; i++) {
		tr(g[i - 1], g[i], S);
		tr(f[i - 1], f[i], S);
		for (int s = 0; s < S; s++) f[i][s] = add(f[i][s], mul(g[i][s], c[s]));
	}
	for (int s = 0; s < S; s++) printf("%d ", f[K][s]);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 10
Accepted
time: 116ms
memory: 29608kb

input:

17 203635058 20 45197
630927925 367691872 854861811 935381440 972493717 952218952 40627765 901726383 333182690 814058886 114559515 857808755 180823985 448291128 904629758 587362495 553139819 808271094 537555635 876810522 460868754 965863351 816253267 677756972 587551773 48482825 12382358 781942390 2...

output:

196898572 306765528 537213886 127286930 159851023 63717087 706071741 435797240 327471764 154687895 775133161 446884277 355140499 730759144 828313812 358804201 563368151 879077306 777389211 488119012 23523875 414748489 31031626 712027375 508390555 892195537 272674444 65777736 725465806 703671740 8558...

result:

ok 131072 numbers

Test #2:

score: 10
Accepted
time: 116ms
memory: 29304kb

input:

17 55303977 20 32265
494363203 155538370 630883878 512423276 148363202 832624635 801640865 903488980 811127763 249184672 605607782 287932872 764562597 387167720 508436523 263243837 25444512 71537379 602424523 577977303 207298251 640159465 917833936 352635217 315477193 937365223 740930608 774925120 2...

output:

289704320 958498566 842657284 940168022 997881125 862052632 724273322 231206605 305893297 43278691 837297755 633518092 730177995 204277846 437293037 502075979 382748699 327548917 26671944 687820882 479587172 348577818 6544646 912745783 388632361 225651778 270406177 724852774 753829405 290426213 3659...

result:

ok 131072 numbers

Test #3:

score: 0
Runtime Error

input:

17 126833065 1000 123430
911917407 121906013 929903588 323429234 139121451 3203442 65035849 409625525 525882288 532577435 971826327 904691827 481756384 47231489 346006246 274441242 584793873 841520735 543444701 644939661 885202827 142653644 180313583 548253835 847010044 216554243 124989074 619408231...

output:


result:


Test #4:

score: 0
Runtime Error

input:

17 621627241 1000 37306
874709248 739473737 912060934 158833941 971188630 744039312 327912594 702720054 185196283 745584702 903434215 484148979 176610819 222341600 961711994 877263458 352785155 12121832 920590333 736755672 428869475 220835314 277186463 787049344 504919397 134827356 59724693 78120026...

output:


result:


Test #5:

score: 0
Runtime Error

input:

1 836026557 1000000000 1
89073685 44729188

output:


result:


Test #6:

score: 0
Runtime Error

input:

8 729700268 1000000000 44
415083631 759858310 528846926 698375322 811429471 668487195 443858087 600445292 190489246 123673503 530450450 76731586 197623863 866555166 743879064 141858132 642913199 103864508 528442021 931490458 969629325 724240247 392146627 32067149 882745389 980834475 140464044 516308...

output:


result:


Test #7:

score: 0
Runtime Error

input:

17 499122177 1000000000 101368
879449681 64374006 2136324 179144921 432405367 443552363 403139437 39083535 353339709 78321779 538844553 158621708 576996457 284607049 353163162 754891442 765538773 579712088 200974213 4059721 644110071 271278034 94792222 726122290 905812908 137101325 873585214 5466611...

output:


result:


Test #8:

score: 0
Runtime Error

input:

17 73054278 1000000000 103328
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:


result:


Test #9:

score: 0
Runtime Error

input:

16 544826057 1000000000 58181
127333103 438073137 374751329 498443816 423416409 925764567 46036736 110186961 233535448 830000756 676728537 294866428 430284448 424338238 337810871 397978 916371232 246055490 114266106 174763813 816533383 346479346 358334243 10507119 464920585 275232506 870081558 38720...

output:


result:


Test #10:

score: 0
Runtime Error

input:

17 596529770 1000000000 121733
359584182 80170529 721719197 271156012 552773637 882685657 619483754 39827609 20656366 82444398 478178854 625533821 736267120 37211948 503896746 770716690 554769769 575127167 638367404 541442475 219866908 428643659 649491821 417360007 540021485 514124438 754101213 3068...

output:


result: