QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#797175#1257. Easy OneNaCly_FishAC ✓38ms35096kbC++141.6kb2024-12-02 18:08:252024-12-02 18:08:26

Judging History

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

  • [2024-12-02 18:08:26]
  • 评测
  • 测评结果:AC
  • 用时:38ms
  • 内存:35096kb
  • [2024-12-02 18:08:25]
  • 提交

answer

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#define N 2000009
#define p 998244353
#define ll long long
using namespace std;

inline int power(int a,int t){
	int res = 1;
	while(t){
		if(t&1) res = (ll)res*a%p;
		a = (ll)a*a%p;
		t >>= 1;
	}
	return res;
}

int fac[N],ifac[N],inv[N];

void init(int n){
	inv[1] = fac[0] = fac[1] = ifac[0] = ifac[1] = 1;
	for(int i=2;i<=n;++i) fac[i] = (ll)fac[i-1]*i%p;
	ifac[n] = power(fac[n],p-2);
	for(int i=n-1;i;--i) ifac[i] = (ll)ifac[i+1]*(i+1)%p;
	for(int i=2;i<=n;++i) inv[i] = (ll)fac[i-1]*ifac[i]%p;
}

inline int binom(int n,int m){
	if(n<m||m<0) return 0;
	return (ll)fac[n]*ifac[m]%p*ifac[n-m]%p;
}

inline int dfac(int n){
	int res = 1;
	for(int i=n;i>0;i-=2) res = (ll)res*i%p;
	return res;
}

int a,b,t;
int f[N];

int main(){
	init(2000003);
	scanf("%d%d%d",&a,&b,&t);
	if(t%2==1 || (b-a)*2>t){
		puts("0");
		return 0;
	}
	b -= a,t /= 2;
	if(b>=0){
		f[0] = (ll)binom(t,b)*dfac(2*t-1)%p;
		f[1] = ((-1-b)-(ll)(1+t)*t)%p*f[0]%p;
		f[1] = -(ll)f[1]*inv[b+1]%p;
		for(int i=2;i<=a;++i){
			int tmp = (2ll*(1-b-i)*i + (b-1)-(ll)(1+t)*t)%p*f[i-1]%p;
			tmp = (tmp + ((ll)i*(i+b-2)+(1-b))%p*f[i-2])%p;
			f[i] = -(ll)tmp*inv[i]%p*inv[i+b]%p;
		}
		printf("%d",(f[a]+p)%p);
	}else{
		f[-b] = (ll)binom(t,-b)*dfac(2*t-1)%p;
		for(int i=-b+1;i<=a;++i){
			int tmp = (2ll*(1-b-i)*i + (b-1)-(ll)(1+t)*t)%p*f[i-1]%p;
			tmp = (tmp + ((ll)i*(i+b-2)+(1-b))%p*f[i-2])%p;
			f[i] = -(ll)tmp*inv[i]%p*inv[i+b]%p;
		}
		printf("%d",(f[a]+p)%p);
	}
	return 0;	
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 16ms
memory: 28284kb

input:

0 0 4

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 24ms
memory: 27464kb

input:

1 4 6

output:

60

result:

ok 1 number(s): "60"

Test #3:

score: 0
Accepted
time: 20ms
memory: 28716kb

input:

10 10 9

output:

0

result:

ok 1 number(s): "0"

Test #4:

score: 0
Accepted
time: 20ms
memory: 27284kb

input:

123 456 999

output:

0

result:

ok 1 number(s): "0"

Test #5:

score: 0
Accepted
time: 24ms
memory: 28628kb

input:

123 456 1000

output:

217690319

result:

ok 1 number(s): "217690319"

Test #6:

score: 0
Accepted
time: 24ms
memory: 28340kb

input:

0 999999 999999

output:

0

result:

ok 1 number(s): "0"

Test #7:

score: 0
Accepted
time: 22ms
memory: 28376kb

input:

0 499999 999998

output:

441249169

result:

ok 1 number(s): "441249169"

Test #8:

score: 0
Accepted
time: 24ms
memory: 27440kb

input:

999999 999999 999999

output:

0

result:

ok 1 number(s): "0"

Test #9:

score: 0
Accepted
time: 38ms
memory: 33124kb

input:

999999 999999 999998

output:

94264534

result:

ok 1 number(s): "94264534"

Test #10:

score: 0
Accepted
time: 16ms
memory: 33080kb

input:

500000 500000 10

output:

278436239

result:

ok 1 number(s): "278436239"

Test #11:

score: 0
Accepted
time: 18ms
memory: 28560kb

input:

123456 567890 999998

output:

200851796

result:

ok 1 number(s): "200851796"

Test #12:

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

input:

123456 565444 676767

output:

0

result:

ok 1 number(s): "0"

Test #13:

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

input:

999999 999999 121233

output:

0

result:

ok 1 number(s): "0"

Test #14:

score: 0
Accepted
time: 36ms
memory: 32972kb

input:

999999 999999 500000

output:

31235134

result:

ok 1 number(s): "31235134"

Test #15:

score: 0
Accepted
time: 31ms
memory: 32972kb

input:

999997 999993 500002

output:

289239002

result:

ok 1 number(s): "289239002"

Test #16:

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

input:

99999 999999 990000

output:

0

result:

ok 1 number(s): "0"

Test #17:

score: 0
Accepted
time: 23ms
memory: 28332kb

input:

0 499999 999996

output:

0

result:

ok 1 number(s): "0"

Test #18:

score: 0
Accepted
time: 23ms
memory: 27700kb

input:

0 0 0

output:

1

result:

ok 1 number(s): "1"

Test #19:

score: 0
Accepted
time: 18ms
memory: 28228kb

input:

0 0 1000000

output:

765860359

result:

ok 1 number(s): "765860359"

Test #20:

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

input:

0 1000000 0

output:

0

result:

ok 1 number(s): "0"

Test #21:

score: 0
Accepted
time: 16ms
memory: 27496kb

input:

0 1000000 1000000

output:

0

result:

ok 1 number(s): "0"

Test #22:

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

input:

1000000 0 0

output:

0

result:

ok 1 number(s): "0"

Test #23:

score: 0
Accepted
time: 25ms
memory: 31416kb

input:

1000000 0 1000000

output:

0

result:

ok 1 number(s): "0"

Test #24:

score: 0
Accepted
time: 36ms
memory: 35096kb

input:

1000000 1000000 0

output:

1

result:

ok 1 number(s): "1"

Test #25:

score: 0
Accepted
time: 38ms
memory: 33168kb

input:

1000000 1000000 1000000

output:

657734828

result:

ok 1 number(s): "657734828"

Test #26:

score: 0
Accepted
time: 21ms
memory: 27796kb

input:

42153 66017 282528

output:

721725208

result:

ok 1 number(s): "721725208"

Test #27:

score: 0
Accepted
time: 26ms
memory: 30496kb

input:

920225 95518 314790

output:

0

result:

ok 1 number(s): "0"

Test #28:

score: 0
Accepted
time: 22ms
memory: 29792kb

input:

761297 88021 384736

output:

0

result:

ok 1 number(s): "0"

Test #29:

score: 0
Accepted
time: 26ms
memory: 29644kb

input:

639368 117522 379998

output:

0

result:

ok 1 number(s): "0"

Test #30:

score: 0
Accepted
time: 16ms
memory: 27976kb

input:

480440 110024 375261

output:

0

result:

ok 1 number(s): "0"

Test #31:

score: 0
Accepted
time: 11ms
memory: 27548kb

input:

321512 138841 445207

output:

0

result:

ok 1 number(s): "0"

Test #32:

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

input:

199583 168342 440469

output:

0

result:

ok 1 number(s): "0"

Test #33:

score: 0
Accepted
time: 21ms
memory: 28636kb

input:

40655 160844 473416

output:

740459120

result:

ok 1 number(s): "740459120"

Test #34:

score: 0
Accepted
time: 20ms
memory: 28292kb

input:

881728 190346 468679

output:

0

result:

ok 1 number(s): "0"

Test #35:

score: 0
Accepted
time: 16ms
memory: 29696kb

input:

722801 219847 538624

output:

0

result:

ok 1 number(s): "0"

Test #36:

score: 0
Accepted
time: 23ms
memory: 27264kb

input:

140788 795655 506181

output:

0

result:

ok 1 number(s): "0"

Test #37:

score: 0
Accepted
time: 33ms
memory: 32432kb

input:

981861 788157 538442

output:

985234443

result:

ok 1 number(s): "985234443"

Test #38:

score: 0
Accepted
time: 18ms
memory: 28444kb

input:

822934 817658 571389

output:

0

result:

ok 1 number(s): "0"

Test #39:

score: 0
Accepted
time: 32ms
memory: 30884kb

input:

664006 772477 566652

output:

652080352

result:

ok 1 number(s): "652080352"

Test #40:

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

input:

542077 838977 636597

output:

0

result:

ok 1 number(s): "0"

Test #41:

score: 0
Accepted
time: 23ms
memory: 27844kb

input:

346150 868479 631860

output:

0

result:

ok 1 number(s): "0"

Test #42:

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

input:

224221 860981 664806

output:

0

result:

ok 1 number(s): "0"

Test #43:

score: 0
Accepted
time: 23ms
memory: 28104kb

input:

65293 890482 697068

output:

0

result:

ok 1 number(s): "0"

Test #44:

score: 0
Accepted
time: 27ms
memory: 32900kb

input:

943365 882985 729330

output:

351354011

result:

ok 1 number(s): "351354011"

Test #45:

score: 0
Accepted
time: 34ms
memory: 33136kb

input:

784437 911801 762276

output:

155945330

result:

ok 1 number(s): "155945330"

Test #46:

score: 0
Accepted
time: 30ms
memory: 30532kb

input:

491726 307429 671948

output:

73584358

result:

ok 1 number(s): "73584358"

Test #47:

score: 0
Accepted
time: 22ms
memory: 30320kb

input:

295799 336931 704894

output:

534052287

result:

ok 1 number(s): "534052287"

Test #48:

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

input:

173870 403431 700157

output:

0

result:

ok 1 number(s): "0"

Test #49:

score: 0
Accepted
time: 23ms
memory: 28056kb

input:

14942 395934 770103

output:

0

result:

ok 1 number(s): "0"

Test #50:

score: 0
Accepted
time: 24ms
memory: 28392kb

input:

893014 387751 765365

output:

0

result:

ok 1 number(s): "0"

Test #51:

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

input:

697087 380253 797627

output:

0

result:

ok 1 number(s): "0"

Test #52:

score: 0
Accepted
time: 28ms
memory: 30840kb

input:

575158 409755 830574

output:

261071668

result:

ok 1 number(s): "261071668"

Test #53:

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

input:

416230 476255 862835

output:

0

result:

ok 1 number(s): "0"

Test #54:

score: 0
Accepted
time: 26ms
memory: 29960kb

input:

257303 468757 895782

output:

86924988

result:

ok 1 number(s): "86924988"

Test #55:

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

input:

135374 498259 891045

output:

0

result:

ok 1 number(s): "0"

Test #56:

score: 0
Accepted
time: 34ms
memory: 33116kb

input:

805665 893203 838400

output:

263337727

result:

ok 1 number(s): "263337727"

Test #57:

score: 0
Accepted
time: 28ms
memory: 32556kb

input:

729675 247218 434658

output:

0

result:

ok 1 number(s): "0"

Test #58:

score: 0
Accepted
time: 27ms
memory: 33132kb

input:

609216 669503 870072

output:

202261436

result:

ok 1 number(s): "202261436"

Test #59:

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

input:

488756 514031 929421

output:

0

result:

ok 1 number(s): "0"

Test #60:

score: 0
Accepted
time: 23ms
memory: 27432kb

input:

691776 682039 463599

output:

0

result:

ok 1 number(s): "0"

Test #61:

score: 0
Accepted
time: 23ms
memory: 28308kb

input:

571316 404780 199469

output:

0

result:

ok 1 number(s): "0"

Test #62:

score: 0
Accepted
time: 30ms
memory: 32608kb

input:

774336 249308 958362

output:

0

result:

ok 1 number(s): "0"

Test #63:

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

input:

330396 671592 116476

output:

0

result:

ok 1 number(s): "0"

Test #64:

score: 0
Accepted
time: 25ms
memory: 30820kb

input:

533416 516121 753582

output:

113683116

result:

ok 1 number(s): "113683116"

Test #65:

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

input:

412956 684129 287759

output:

0

result:

ok 1 number(s): "0"

Test #66:

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

input:

292496 406870 347109

output:

0

result:

ok 1 number(s): "0"

Test #67:

score: 0
Accepted
time: 20ms
memory: 28560kb

input:

245891 134953 893416

output:

299302885

result:

ok 1 number(s): "299302885"

Test #68:

score: 0
Accepted
time: 16ms
memory: 27928kb

input:

125431 880717 952766

output:

0

result:

ok 1 number(s): "0"

Test #69:

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

input:

906207 725245 810423

output:

0

result:

ok 1 number(s): "0"

Test #70:

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

input:

207991 569774 546293

output:

0

result:

ok 1 number(s): "0"

Test #71:

score: 0
Accepted
time: 11ms
memory: 27468kb

input:

665287 992058 981707

output:

0

result:

ok 1 number(s): "0"

Test #72:

score: 0
Accepted
time: 33ms
memory: 33056kb

input:

868307 836586 139820

output:

168754021

result:

ok 1 number(s): "168754021"

Test #73:

score: 0
Accepted
time: 26ms
memory: 33064kb

input:

747847 882807 776926

output:

679383214

result:

ok 1 number(s): "679383214"