QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#814811#6112. Village Planning通顶雪道 (Qiuyang Mang, Youran Sun, Qingshuo Guo)RE 1069ms37588kbC++145.1kb2024-12-14 20:51:152024-12-14 20:51:16

Judging History

This is the latest submission verdict.

  • [2024-12-14 20:51:16]
  • Judged
  • Verdict: RE
  • Time: 1069ms
  • Memory: 37588kb
  • [2024-12-14 20:51:15]
  • Submitted

answer

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

const int mod = 998244353;
const int g = 3;

inline void uadd(int &a, int b) { a += b - mod; a += (a >> 31) & mod; }
inline void usub(int &a, int b) { a -= b; a += (a >> 31) & mod; }
inline void umul(int &a, int b) { a = 1LL * a * b % mod; }

int add(int a, int b) { uadd(a, b); return a; }
int sub(int a, int b) { usub(a, b); return a; }
int mul(int a, int b) { umul(a, b); return a; }

int qp(int x, long long y = mod - 2) {
	int ret = 1;
	for (; y; y >>= 1, umul(x, x)) if (y & 1) umul(ret, x);
	return ret;
}

int r[1 << 20], w[1 << 20];

void fft_init(int n) {
	int k = 0; while((1 << k) < n) ++k;
	rep(i, n - 1) if (i) r[i] = (r[i >> 1] >> 1) | ((i & 1) << (k - 1));
	for (int h = 1; h < n; h <<= 1) {
		int x = qp(g, (mod - 1) / (h << 1));
		rep(i, h) w[h + i] = i ? mul(x, w[h + i - 1]) : 1;
	}
}

void fft(int *a, int n, bool f = 0) {
	rep(i, n - 1) if (i && i < r[i]) swap(a[i], a[r[i]]);
	for (int h = 1; h < n; h <<= 1) {
		for (int i = 0; i < n; i += h << 1) {
			rep(j, h) {
				int v = mul(a[i + h + j], w[h + j]);
				a[i + h + j] = sub(a[i + j], v);
				uadd(a[i + j], v);
			}
		}
	}
	if (f) {
		reverse(a + 1, a + n);
		int inv = qp(n);
		rep(i, n) umul(a[i], inv);
	}
}


struct Poly: vector<int> {
public:
	Poly(int n, int x = 0) {
		clear();
		resize(n, x);
	}
	Poly modn(int n) const {
		Poly ans(*this);
		ans.resize(n);
		return ans;
	}
	
	Poly operator + (const Poly &o) const {
		Poly ans(max(size(), o.size()));
		rep(i, size()) uadd(ans[i], at(i));
		rep(i, o.size()) uadd(ans[i], o.at(i));
		return ans;
	}
	
	Poly operator - (const Poly &o) const {
		Poly ans(max(size(), o.size()));
		rep(i, size()) uadd(ans[i], at(i));
		rep(i, o.size()) usub(ans[i], o.at(i));
		return ans;
	}
	
	Poly operator * (int c) const {
		Poly ans(size());
		rep(i, size()) ans[i] = mul(at(i), c);
		return ans;
	}
	
	Poly operator * (const Poly &o) const {
		static int A[1 << 20], B[1 << 20];
		int n = size() + o.size() - 1;
		Poly ans(n);
		if (false && min(size(), o.size()) <= 32) {
			rep(i, size()) rep(j, o.size())
				uadd(ans[i + j], mul(at(i), o.at(j)));
			return ans;
		}
		int sz = 1; for (; sz < n; sz <<= 1);
		fft_init(sz);
		memset(A, 0, sz << 2);
		memset(B, 0, sz << 2);
		rep(i, size()) A[i] = at(i);
		rep(i, o.size()) B[i] = o.at(i);
		fft(A, sz);
		fft(B, sz);
		rep(i, sz) umul(A[i], B[i]);
		fft(A, sz, 1);
		rep(i, n) ans[i] = A[i];
		return ans;
	}
	
	Poly deriv() const {
		Poly ans(size() - 1);
		rep(i, size() - 1) ans[i] = mul(i + 1, at(i + 1));
		return ans;
	}
	
	Poly inte() const {
		Poly ans(size() + 1);
		rep(i, size()) ans[i + 1] = mul(qp(i + 1), at(i));
		return ans;
	}
	
	Poly inv() const {
		if (size() == 1) {
			Poly ans(1);
			ans[0] = qp(at(0));
			return ans;
		}
		int n = size(), n0 = (n + 1) >> 1;
		Poly h = *this, h0 = h.modn(n0), f0 = h0.inv().modn(n);
		return (f0 * 2 - f0 * f0 * h).modn(n);
	}
	
	Poly ln() const {
		assert(at(0) == 1);
		return (deriv() * inv()).inte().modn(size());
	}
	
	Poly exp() const {
		if (size() == 1) {
			Poly ans(1);
			assert(at(0) == 0);
			ans[0] = 1;
			return ans;
		}
		int n = size(), n0 = (n + 1) >> 1;
		Poly h = *this, h0 = h.modn(n0), f0 = h0.exp().modn(n);
		return (f0 * (Poly(1, 1) + h - f0.ln())).modn(n); 
	}
	
	Poly pow(int k) const {
		return (ln() * k).exp();
	}
} ;

const int maxn = 1e5 + 5;

int n, K;
int a[5];
int fac[maxn], ifac[maxn];

int main(){
	scanf("%d%d", &n, &K);
	for (int i = 0; i <= K; ++i) scanf("%d", a + i);
	if (K == 0) {
		for (int i = 2; i <= n; ++i) printf("%d ", qp(a[0], 1ll * i * (i - 1) / 2));
		puts("");
		return 0;
	}
	
	fac[0] = 1; for (int i = 1; i <= n; ++i) fac[i] = 1ll * fac[i - 1] * i % mod;
	ifac[n] = qp(fac[n]); for (int i = n - 1; ~i; --i) ifac[i] = 1ll * ifac[i + 1] * (i + 1) % mod;
	
	int v1 = 1ll * a[1] * qp(a[0]) % mod;

	Poly tree(n + 1);
	for (int i = 1; i <= n; ++i) {
		tree[i] = 1ll * (i == 1 ? 1 : qp(i, i - 2)) * ifac[i] % mod * qp(v1, 1ll * i * (i - 1) / 2) % mod;
	}
	if (K == 1) {
		Poly trees = tree.exp();
		
		for (int i = 2; i <= n; ++i) {
			int res = 1ll * fac[i] * trees[i] % mod * qp(a[0], 1ll * i * (i - 1) / 2) % mod;
			printf("%d ", res);
		}
		puts("");
		return 0;
	}
	
	int v2 = 1ll * a[1] * qp(a[2]) % mod;
	Poly rooted(n + 1);
	for (int i = 1; i <= n; ++i) {
		rooted[i] = 1ll * qp(i, i - 1) * ifac[i] % mod * qp(v2, 1ll * i * (i - 1) / 2) % mod;
	}
	Poly cycle_based = (Poly(1, 1) - rooted).ln() * (-1);
	cycle_based = cycle_based - rooted;
	cycle_based = cycle_based - rooted * rooted * qp(2);
	cycle_based = cycle_based * qp(2);
	
	int v3 = 1ll * a[2] * qp(a[0]) % mod;
	for (int i = 1; i <= n; ++i) {
		cycle_based[i] = 1ll * cycle_based[i] * qp(v3, 1ll * i * (i - 1) / 2) % mod;
	}

	Poly connected = tree + cycle_based;
	
	Poly graph = connected.exp();
	for (int i = 2; i <= n; ++i) {
		int res = 1ll * graph[i] * fac[i] % mod * qp(a[0], 1ll * i * (i - 1) / 2) % mod;
		printf("%d ", res);
	}
	puts("");
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 5888kb

input:

4 0
2

output:

2 8 64 

result:

ok 3 number(s): "2 8 64"

Test #2:

score: 0
Accepted
time: 1ms
memory: 7912kb

input:

5 1
3 4

output:

7 327 96721 169832849 

result:

ok 4 number(s): "7 327 96721 169832849"

Test #3:

score: 0
Accepted
time: 2ms
memory: 9924kb

input:

6 2
5 6 7

output:

11 1566 3000672 306031599 466869291 

result:

ok 5 number(s): "11 1566 3000672 306031599 466869291"

Test #4:

score: 0
Accepted
time: 1ms
memory: 7980kb

input:

7 3
8 9 10 11

output:

17 5427 31856976 326774674 449014006 997476587 

result:

ok 6 numbers

Test #5:

score: 0
Accepted
time: 19ms
memory: 3848kb

input:

100000 0
12345678

output:

12345678 644056040 211986440 366246078 129089719 221368866 283124263 92530495 602608963 591370683 990229283 164971576 676013258 861632667 266225306 38421683 734331905 954922439 924295443 581924621 641884577 953780417 395588140 569420628 269024687 923445182 812638938 221225256 415075963 833284693 182...

result:

ok 99999 numbers

Test #6:

score: 0
Accepted
time: 15ms
memory: 5856kb

input:

100000 0
1

output:

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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

result:

ok 99999 numbers

Test #7:

score: 0
Accepted
time: 19ms
memory: 3804kb

input:

100000 0
998244352

output:

998244352 998244352 1 1 998244352 998244352 1 1 998244352 998244352 1 1 998244352 998244352 1 1 998244352 998244352 1 1 998244352 998244352 1 1 998244352 998244352 1 1 998244352 998244352 1 1 998244352 998244352 1 1 998244352 998244352 1 1 998244352 998244352 1 1 998244352 998244352 1 1 998244352 99...

result:

ok 99999 numbers

Test #8:

score: 0
Accepted
time: 14ms
memory: 6148kb

input:

73812 0
3141592

output:

3141592 502595211 930804156 494129912 890907052 937804910 155794517 312377295 141669564 196035410 418956765 791193589 756093320 361837829 72344530 578759786 313970847 636643125 747705681 676578954 596656200 395491001 81642642 219037384 969715473 813221369 410880484 305249904 367704238 564789451 2855...

result:

ok 73811 numbers

Test #9:

score: 0
Accepted
time: 393ms
memory: 25488kb

input:

100000 1
1 1

output:

2 7 38 291 2932 36961 561948 10026505 205608536 774463267 589147789 829299664 243375906 66263611 965270387 154777431 601662699 929537049 893635200 219507261 392236640 775545378 714600599 56551872 187837583 189925757 50494333 611131417 258806070 413153890 109986030 618449809 731781234 408507333 28278...

result:

ok 99999 numbers

Test #10:

score: 0
Accepted
time: 382ms
memory: 25932kb

input:

100000 1
3127218 14172129

output:

17299347 544607138 680226212 305869647 912178269 916199911 125174848 307445424 256318706 16877857 462417641 298914440 279886537 287167270 564531297 111249855 460247698 805600287 58601732 199348757 45669640 366398551 149741463 906663559 976291245 366968697 90322856 347392377 225958266 867152353 84926...

result:

ok 99999 numbers

Test #11:

score: 0
Accepted
time: 390ms
memory: 27164kb

input:

100000 1
998244352 998244352

output:

998244351 998244346 38 291 998241421 998207392 561948 10026505 792635817 223781086 589147789 829299664 754868447 931980742 965270387 154777431 396581654 68707304 893635200 219507261 606007713 222698975 714600599 56551872 810406770 808318596 50494333 611131417 739438283 585090463 109986030 618449809 ...

result:

ok 99999 numbers

Test #12:

score: 0
Accepted
time: 395ms
memory: 26580kb

input:

100000 1
1 998244352

output:

0 998244348 2 211 998244033 998216494 84828 7784137 960946049 213292735 225093311 837100977 925933466 413576187 774455991 727906343 96771916 604528716 51075694 784377733 280737476 769195767 101561083 881507340 731348568 702337822 594671739 556715938 256133261 758927779 131639043 21463936 216796323 5...

result:

ok 99999 numbers

Test #13:

score: 0
Accepted
time: 396ms
memory: 27280kb

input:

99999 1
9 99

output:

108 2935683 905844104 884930131 610271296 167794683 874562044 144589021 654900997 739155189 156126745 259210590 364360898 474007353 202797476 105542 287700849 491427578 861300599 773784742 92662708 677626795 300989836 644734128 859127006 985588013 222572430 241496128 218066520 262003703 218365187 63...

result:

ok 99998 numbers

Test #14:

score: 0
Accepted
time: 1044ms
memory: 37540kb

input:

100000 2
1 1 1

output:

2 8 57 608 8524 145800 2918123 66617234 706669081 384399752 501322809 82724887 450722832 428972217 181542374 652797702 609850214 874870984 765605342 147495034 696875380 556350159 263684494 785985697 927559849 434848582 197878990 406693583 792170563 800087590 373988208 3254512 227893387 739644336 696...

result:

ok 99999 numbers

Test #15:

score: 0
Accepted
time: 1069ms
memory: 37588kb

input:

100000 2
998244352 998244352 998244352

output:

998244351 998244345 57 608 998235829 998098553 2918123 66617234 291575272 613844601 501322809 82724887 547521521 569272136 181542374 652797702 388394139 123373369 765605342 147495034 301368973 441894194 263684494 785985697 70684504 563395771 197878990 406693583 206073790 198156763 373988208 3254512 ...

result:

ok 99999 numbers

Test #16:

score: -100
Runtime Error

input:

100000 2
281937 171272 818181

output:


result: