QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#345976#8312. Fly Me To The Moonblack_moonriseAC ✓7037ms93632kbC++146.4kb2024-03-07 18:40:512024-03-07 18:40:52

Judging History

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

  • [2024-03-07 18:40:52]
  • 评测
  • 测评结果:AC
  • 用时:7037ms
  • 内存:93632kb
  • [2024-03-07 18:40:51]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
#define MP make_pair
#define PB push_back
#define FF first
#define SS second

typedef long long ll;
const int mod = 998244353;
const int maxsize = 2222;
const int proot = 3;
const int maxn = 2222;

ll qpow(ll x, ll y) {
	ll ret = 1;
	while(y) {
		if(y&1) ret = ret * x % mod;
		x = x * x % mod;
		y >>= 1;
	}
	return ret;
}

struct ntt {
	int n, M, w_pre[maxsize], inv[maxsize];
	ntt() {
		M = 1;
		while(M*2<maxsize) M <<= 1;
		int w = qpow(proot, (mod - 1) / M);
		w_pre[0] = 1;
		for(int i=1; i<=M; i++) w_pre[i] = 1ll * w_pre[i-1] * w % mod;
		inv[1] = 1;
		for(int i=2; i<maxsize; i++) inv[i] = mod - 1ll * inv[mod % i] * (mod / i) % mod;
	}
	void FFTinit(int sz) {
		n = 1;
		while(n < sz) n <<= 1;
		if (n > M) cout<<n<<endl;
		assert(n <= M);
	}
	void FFT(int a[], int coef) {
		typedef unsigned long long ull;
		const ull mod2 = 1ull * mod * mod;
		static ull na[maxsize];
		for(int i=0, j=0; i<n; i++) {
			na[j] = a[i] < 0 ? (a[i] + mod) : a[i];
			for(int l=n>>1; (j^=l) < l; l>>=1) continue;
		}
		static int w[maxsize];
		for(int l=1; l<n; l<<=1) {
			int l2 = l + l, u = M / l2;
			if(coef == 1) {
				for(int j=0, t=0; j<l; j++, t+=u) w[j] = w_pre[t];
			}
			else {
				for(int j=0, t=M; j<l; j++, t-=u) w[j] = w_pre[t];
			}
			for(int i=0; i<n; i+=l2) {
				for(int j=0; j<l; j++) {
					ull tmp = na[i+j+l] % mod * w[j];
					na[i+j+l] = na[i+j] - tmp + mod2;
					na[i+j] += tmp;
				}
			}
			if(l == (1 << 8) || l == (1 << 16)) for(int i=0; i<n; i++) na[i] %= mod;
		}
		for(int i=0; i<n; i++) a[i] = 1ll * na[i] % mod * (coef == -1?inv[n]:1) % mod;
	}
	vector<int> multi(vector<int> &A, vector<int> &B, int N = -1) {
		if(N == -1) N = max(0, int(A.size() + B.size()) - 1);
		FFTinit(A.size() + B.size());
		static int a[maxsize], b[maxsize];
		for(int i=0; i<n; i++) a[i] = i < A.size() ? A[i] % mod : 0;
		for(int i=0; i<n; i++) b[i] = i < B.size() ? B[i] % mod : 0;
		FFT(a, 1);
		FFT(b, 1);
		for(int i=0; i<n; i++) a[i] = 1ll * a[i] * b[i] % mod;
		FFT(a, -1);
		vector<int> ret(N);
		for(int i=0; i<N; i++) ret[i] = a[i];
		return ret;
	}
} M1;

namespace MUL {
	int a[maxn][maxn], b[maxn][maxn], c[maxn][maxn];
	int sz;
	void FFT(int a[maxn][maxn], int coef) {
		if (coef==1) {
			for (int i=0; i<sz; i++) {
				M1.FFT(a[i], 1);
			}
			for (int i=0; i<sz; i++) {
				for (int j=0; j<sz; j++) {
					if (i<j) {
						swap(a[i][j], a[j][i]);
					}
				}
			}
			for (int i=0; i<sz; i++) {
				M1.FFT(a[i], 1);
			}
			for (int i=0; i<sz; i++) {
				for (int j=0; j<sz; j++) {
					if (i<j) {
						swap(a[i][j], a[j][i]);
					}
				}
			}
		} else {
			for (int i=0; i<sz; i++) {
				for (int j=0; j<sz; j++) {
					if (i<j) {
						swap(a[i][j], a[j][i]);
					}
				}
			}
			for (int i=0; i<sz; i++) {
				M1.FFT(a[i], -1);
			}
			for (int i=0; i<sz; i++) {
				for (int j=0; j<sz; j++) {
					if (i<j) {
						swap(a[i][j], a[j][i]);
					}
				}
			}
			for (int i=0; i<sz; i++) {
				M1.FFT(a[i], -1);
			}
		}
	}
	void mul(int an, int am, int bn, int bm) {
		int _sz = max(an + bn, am + bm) + 1;
		M1.FFTinit(_sz);
		sz = M1.n;

		for (int i=0; i<sz; i++) for (int j=0; j<sz; j++) {
			a[i][j] = i < an && j < am ? a[i][j] % mod : 0;
			b[i][j] = i < bn && j < bm ? b[i][j] % mod : 0;
		}
		FFT(a, 1);
		FFT(b, 1);
		for (int i=0; i<sz; i++) for (int j=0; j<sz; j++) {
			c[i][j] = 1ll * a[i][j] * b[i][j] % mod;
		}
		FFT(c, -1);
	}
}

int fac[maxn], invf[maxn];


int n, m;
int d[maxn];
int f[maxn][maxn], g[maxn][maxn], dp[maxn];
vector<pair<int,int> > pt;
void upd(int &x, int v) {
	x = (x+v)%mod;
}
int a[maxn][maxn];
void cont(int xl, int xr, int yl, int yr, int XL, int XR, int YL, int YR) {
	for (int i=xl; i<=xr; i++) for (int j=yl; j<=yr; j++) {
		MUL::a[i-xl][j-yl] = f[i][j];
	}
	for (int i=0; i<=XR-XL; i++) for (int j=0; j<=YR-YL; j++) {
		MUL::b[i][j] = g[i][j];
	}
	MUL::mul(xr-xl+1, yr-yl+1, XR-XL+1, YR-YL+1);

	for (int i=XL; i<=XR; i++) for (int j=YL; j<=YR; j++) {
		if (i>=xl && i<=xr && j>=yl && j<=yr) continue;
		if (i>=xl && j>=yl) upd(a[i][j], MUL::c[i-xl][j-yl]);
	}
}
void solve(int xl, int xr, int yl, int yr) {
	if (xl==xr) {
		f[xl][yl] = a[xl][yl] + (xl==0 && yl==0);
		return;
	}
	int xm = xl + xr >> 1;
	int ym = yl + yr >> 1;
	
	solve(xl, xm, yl, ym);
	cont(xl, xm, yl, ym, xl, xr, yl, yr);

	solve(xm+1, xr, yl, ym);
	cont(xm+1, xr, yl, ym, xl, xr, yl, yr);
	
	solve(xl, xm, ym+1, yr);
	cont(xl, xm, ym+1, yr, xl, xr, yl, yr);

	solve(xm+1, xr, ym+1, yr);
}
void calc_f() {
	// f[0][0] = 1;
	// for (int i=0; i<=1000; i++) for (int j=0; j<=1000; j++) {
	// 	for (int x=0; x<=10; x++) for (int y=0; y<=10; y++) {
	// 		upd(f[i+x][j+y], 1ll * f[i][j] * g[x][y] % mod);
	// 	}
	// }
	solve(0, 1023, 0, 1023);
}

int getf(pair<int,int> x, pair<int,int> y) {
	int i = y.FF - x.FF;
	int j = y.SS - x.SS;
	if (i < 0 || j < 0) return 0;
	return f[i][j];
}
int main() {
	// MUL::a[0][1] = 1;
	// MUL::a[1][0] = 2;
	// MUL::b[0][0] = 3;
	// MUL::b[1][1] = 4;
	// MUL::mul(2, 2, 2, 2);
	// for (int i=0; i<4; i++) {
	// 	for (int j=0; j<4; j++) {
	// 		cout<<MUL::c[i][j]<<" ";
	// 	}cout<<endl;
	// }
	
	fac[0] = 1;
	for(int i=1; i<maxn; i++) fac[i] = 1ll * i * fac[i-1] % mod;
	invf[maxn-1] = qpow(fac[maxn-1], mod - 2);
	for(int i=maxn-1; i>=1; i--) invf[i-1] = 1ll * i * invf[i] % mod;
	
	scanf("%d%d", &n, &m);
	for (int i=1; i<=n; i++) {
		scanf("%d", &d[i]);
	}
	for (int i=1; i<=m; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		pt.PB(MP(x, y));
	}
	pt.PB(MP(0, 0));

	for (int i=1; i<=n; i++) {
		for (int j=0; j<=d[i]; j++) {
			int tsqr = d[i] * d[i] - j * j;
			int tmp = sqrt(tsqr);
			while ((tmp+1)*(tmp+1) <= tsqr) tmp++;
			g[j][tmp] ++;
		}
	}
	for (int i=0; i<=1000; i++) {
		for (int j=1000; j>0; j--) {
			g[i][j-1] = (g[i][j-1] + g[i][j]) % mod;
		}
	}
	g[0][0] = 0;

	calc_f();
	// for (int i=0; i<10; i++) {
	// 	for (int j=0; j<10; j++) {
	// 		cout<<f[i][j]<<" ";
	// 	}cout<<endl;
	// }

	sort(pt.begin(), pt.end());
	reverse(pt.begin(), pt.end());

	for (int i=0; i<pt.size(); i++) {
		dp[i] = getf(pt[i], MP(1000, 1000));
		for (int j=0; j<i; j++) {
			dp[i] = (dp[i] - 1ll * dp[j] * getf(pt[i], pt[j])) % mod;
		}
	}
	cout<<(dp[pt.size()-1] + mod) % mod<<endl;
	return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 6963ms
memory: 89188kb

input:

1 0
1

output:

472799582

result:

ok single line: '472799582'

Test #2:

score: 0
Accepted
time: 6945ms
memory: 88764kb

input:

1 1
1
500 500

output:

447362327

result:

ok single line: '447362327'

Test #3:

score: 0
Accepted
time: 6924ms
memory: 89900kb

input:

1 0
2

output:

277036758

result:

ok single line: '277036758'

Test #4:

score: 0
Accepted
time: 6920ms
memory: 88632kb

input:

1 1
402
305 914

output:

902644270

result:

ok single line: '902644270'

Test #5:

score: 0
Accepted
time: 6955ms
memory: 89312kb

input:

1 10
819
767 245
718 363
832 537
648 98
622 692
995 435
641 522
1000 524
220 848
657 772

output:

728068212

result:

ok single line: '728068212'

Test #6:

score: 0
Accepted
time: 6942ms
memory: 89288kb

input:

1 100
51
779 670
872 824
190 278
764 704
804 857
215 41
43 329
735 229
733 463
594 905
740 538
245 254
556 174
523 388
0 722
464 464
62 31
554 24
935 438
738 751
250 849
803 437
856 887
745 187
52 845
855 613
344 256
705 694
897 743
682 796
966 471
268 430
937 160
629 629
641 98
329 470
49 650
463 6...

output:

517392311

result:

ok single line: '517392311'

Test #7:

score: 0
Accepted
time: 7037ms
memory: 88148kb

input:

1 1000
60
654 936
693 232
484 105
592 624
118 698
490 632
411 327
487 16
51 399
408 241
39 574
39 994
777 881
506 360
445 779
186 319
651 673
939 828
845 950
81 613
747 548
176 72
283 422
866 639
256 790
168 672
551 308
265 204
542 587
800 837
299 347
485 296
410 832
894 123
785 795
705 20
360 762
2...

output:

226697311

result:

ok single line: '226697311'

Test #8:

score: 0
Accepted
time: 6938ms
memory: 90576kb

input:

10 1
668 228 643 930 253 838 234 427 994 555
769 217

output:

706413856

result:

ok single line: '706413856'

Test #9:

score: 0
Accepted
time: 6906ms
memory: 90064kb

input:

10 10
210 428 49 365 404 258 968 520 718 191
240 37
665 794
444 403
492 764
38 1
549 456
32 847
95 499
490 875
983 553

output:

866541606

result:

ok single line: '866541606'

Test #10:

score: 0
Accepted
time: 6904ms
memory: 89472kb

input:

10 100
234 300 17 327 773 617 460 612 25 853
332 250
788 770
578 304
378 268
648 555
820 600
989 317
319 383
904 612
22 17
511 183
896 125
963 958
722 984
681 766
420 198
492 686
285 634
15 40
531 325
414 10
581 72
93 528
771 235
906 696
255 785
493 858
804 452
899 585
824 334
798 579
161 357
615 20...

output:

857409499

result:

ok single line: '857409499'

Test #11:

score: 0
Accepted
time: 6957ms
memory: 89948kb

input:

10 1000
433 514 452 478 193 55 745 40 365 655
143 730
490 83
890 273
699 469
293 532
971 535
204 959
370 992
238 858
306 647
273 701
661 560
9 857
27 635
564 666
83 239
640 989
738 290
316 584
687 656
587 263
969 245
782 395
958 638
551 128
570 105
776 244
442 723
708 963
527 978
714 479
331 613
373...

output:

99542416

result:

ok single line: '99542416'

Test #12:

score: 0
Accepted
time: 6898ms
memory: 92104kb

input:

100 1
164 898 529 41 491 208 409 533 860 311 271 48 914 918 256 757 19 647 652 343 880 995 504 120 864 995 499 86 285 823 793 816 445 147 923 501 314 789 733 861 507 305 623 566 249 669 933 528 955 461 511 665 874 472 497 331 957 313 756 665 463 735 595 101 348 397 471 477 479 315 180 409 183 739 91...

output:

30592831

result:

ok single line: '30592831'

Test #13:

score: 0
Accepted
time: 6910ms
memory: 90696kb

input:

100 10
689 629 128 228 488 666 155 67 260 881 474 235 69 580 605 622 791 551 274 3 90 106 875 180 905 787 566 632 75 865 300 521 61 618 602 575 487 806 667 276 914 193 643 646 760 397 517 249 252 214 991 530 709 708 817 220 224 692 146 407 547 720 515 772 131 754 745 778 583 773 943 557 602 644 954 ...

output:

523635681

result:

ok single line: '523635681'

Test #14:

score: 0
Accepted
time: 6932ms
memory: 91044kb

input:

100 100
95 994 231 565 335 495 270 478 781 36 769 597 839 828 489 262 736 223 835 21 136 11 865 239 113 534 479 687 91 470 143 682 24 697 206 387 449 381 260 792 863 9 16 506 131 690 106 905 470 48 927 86 665 366 545 808 567 317 124 144 734 193 826 332 82 954 272 783 994 381 279 679 809 809 4 559 94...

output:

226829327

result:

ok single line: '226829327'

Test #15:

score: 0
Accepted
time: 6940ms
memory: 93292kb

input:

100 1000
122 81 18 561 601 538 804 877 55 943 955 751 206 881 249 227 640 846 6 935 544 383 628 688 609 898 25 669 837 272 848 595 599 376 280 855 953 122 779 687 751 29 97 18 666 571 123 11 223 527 88 26 901 493 923 371 947 411 378 228 423 816 497 219 439 228 573 183 156 144 426 610 11 849 310 893 ...

output:

801536119

result:

ok single line: '801536119'

Test #16:

score: 0
Accepted
time: 6933ms
memory: 90648kb

input:

1000 1
347 291 904 415 766 616 892 80 210 2 855 907 49 874 156 630 623 472 636 474 871 591 458 258 398 844 133 304 822 802 393 360 789 888 566 875 355 777 944 622 831 195 941 968 259 49 650 927 564 305 662 956 187 967 70 762 390 616 264 187 383 832 543 507 348 693 181 939 350 465 84 719 138 779 52 7...

output:

949510956

result:

ok single line: '949510956'

Test #17:

score: 0
Accepted
time: 6977ms
memory: 90004kb

input:

1000 10
550 515 534 170 50 545 557 637 312 64 715 686 618 743 11 58 829 992 668 519 314 9 961 173 719 405 249 728 772 793 856 983 239 647 565 328 784 902 498 850 773 687 376 473 447 746 472 533 20 959 762 523 875 246 770 747 307 975 102 24 372 883 833 635 260 97 996 793 539 145 607 568 95 453 972 13...

output:

543205049

result:

ok single line: '543205049'

Test #18:

score: 0
Accepted
time: 6964ms
memory: 92844kb

input:

1000 100
1000 561 798 648 552 683 817 828 176 516 923 627 308 136 362 867 562 911 478 12 28 965 706 374 666 360 506 416 69 262 983 26 61 532 580 724 436 103 125 412 561 519 907 517 318 215 801 322 123 495 706 503 160 938 273 241 871 120 158 360 535 141 528 628 674 664 326 950 656 285 77 634 146 756 ...

output:

557427721

result:

ok single line: '557427721'

Test #19:

score: 0
Accepted
time: 6905ms
memory: 91476kb

input:

1000 1000
520 999 552 931 480 348 671 930 534 80 510 4 176 583 686 73 81 239 523 968 447 468 517 286 523 285 929 366 764 533 310 580 524 635 33 153 49 146 57 58 54 250 115 705 207 229 111 266 776 787 273 191 143 342 257 157 38 663 995 53 586 135 360 540 78 479 884 435 825 808 438 295 523 380 810 658...

output:

410377569

result:

ok single line: '410377569'

Test #20:

score: 0
Accepted
time: 6959ms
memory: 89800kb

input:

1000 1000
630 843 959 696 75 966 691 982 390 44 863 380 467 293 94 96 415 411 161 497 844 109 629 520 209 248 672 754 608 553 552 447 503 868 292 854 848 512 849 15 120 497 70 671 707 29 952 544 302 159 863 886 788 160 63 27 27 600 912 555 476 809 511 225 182 701 195 657 363 275 392 691 249 590 135 ...

output:

625394011

result:

ok single line: '625394011'

Test #21:

score: 0
Accepted
time: 6949ms
memory: 90556kb

input:

1000 1000
553 29 586 864 467 447 950 526 232 354 866 48 566 98 600 10 667 754 262 683 344 374 641 56 33 945 141 175 255 575 341 165 806 941 985 209 79 652 395 86 327 794 161 869 198 400 815 64 457 597 882 833 561 209 725 745 450 363 808 353 933 92 4 988 558 370 728 259 934 238 79 976 474 174 16 955 ...

output:

373678731

result:

ok single line: '373678731'

Test #22:

score: 0
Accepted
time: 6932ms
memory: 91940kb

input:

1000 1000
1 186 432 753 430 425 46 836 652 389 195 429 575 809 901 935 24 697 358 545 627 975 980 343 7 167 762 519 298 347 118 422 923 855 577 657 470 750 138 572 572 275 835 54 672 25 482 435 330 700 450 353 264 854 95 907 824 835 494 345 304 733 290 366 983 672 24 169 649 535 740 21 454 437 554 8...

output:

663460363

result:

ok single line: '663460363'

Test #23:

score: 0
Accepted
time: 6979ms
memory: 93632kb

input:

1000 1000
411 936 467 652 654 870 544 32 4 510 859 984 38 130 45 311 103 127 539 741 78 540 663 707 537 614 647 480 325 943 716 583 70 754 565 871 318 473 705 161 934 704 960 454 30 687 571 519 387 531 584 547 715 373 919 140 187 513 999 826 338 825 394 894 779 216 244 368 823 728 104 611 40 900 467...

output:

61802460

result:

ok single line: '61802460'

Test #24:

score: 0
Accepted
time: 6916ms
memory: 93140kb

input:

1000 1000
551 193 944 906 622 45 236 187 186 950 603 74 279 941 962 226 557 41 588 681 856 753 46 564 553 836 508 88 3 169 283 170 503 863 165 600 96 711 112 966 344 485 119 643 10 498 815 945 557 453 931 536 239 373 961 27 808 368 507 233 147 864 671 630 144 1 368 967 149 277 186 434 552 480 601 34...

output:

849139143

result:

ok single line: '849139143'

Test #25:

score: 0
Accepted
time: 6909ms
memory: 92220kb

input:

1000 1000
189 942 273 771 441 891 200 358 733 973 938 345 979 806 417 289 424 503 526 823 997 89 684 543 394 691 283 833 910 336 710 148 504 86 877 790 617 127 844 653 791 339 186 529 260 741 331 95 637 794 983 200 804 61 664 95 375 614 432 151 190 278 17 619 728 252 739 660 255 323 353 183 983 706 ...

output:

15494064

result:

ok single line: '15494064'

Test #26:

score: 0
Accepted
time: 6891ms
memory: 91824kb

input:

1000 1000
411 789 753 186 495 203 417 324 490 424 195 480 314 23 663 218 12 747 124 390 134 38 218 536 291 840 174 908 474 767 313 167 575 9 857 427 313 27 959 935 258 70 472 957 747 228 205 939 293 303 626 802 712 283 658 346 208 383 889 204 99 640 801 966 828 742 534 11 259 734 226 129 843 350 50 ...

output:

81830009

result:

ok single line: '81830009'

Extra Test:

score: 0
Extra Test Passed