QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#235127#6333. Festivals in JOI Kingdom 2275307894a#100 ✓2874ms4940kbC++141.3kb2023-11-02 14:39:582024-07-04 02:22:39

Judging History

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

  • [2024-07-04 02:22:39]
  • 评测
  • 测评结果:100
  • 用时:2874ms
  • 内存:4940kb
  • [2023-11-02 14:39:58]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar() 
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;using LL=__int128;
const int N=2e4+5,M=5e5+5,K=(1<<25)+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(time(0));
int n,p;ll f[N][2],frc[N*2],inv[N*2];
ll calc(int x,int y){return x>=y&&y>=0?frc[x]*inv[x-y]%p:0;}
int main(){
	int i,j,h;scanf("%d%d",&n,&p);
	inv[1]=1;for(i=2;i<=2*n;i++) inv[i]=(p-inv[p%i])*(p/i)%p;
	for(inv[0]=frc[0]=i=1;i<=2*n;i++) frc[i]=frc[i-1]*i%p,inv[i]=inv[i-1]*inv[i]%p;
	f[0][0]=f[0][1]=1;
	for(i=1;i<=n;i++){
		for(j=1;j<=i;j++){
			ll w=calc(2*i-1-j,j-1)*f[i-j][0]%p;
			f[i][1]+=j*w;
			f[i][0]+=w;
			if(j>1){
				w=(j-1)*calc(2*i-1-j,j-2)%p*f[i-j][1]%p;
				f[i][0]+=w;
				f[i][1]+=j*w;
			} 
		}
		f[i][0]%=p;f[i][1]%=p;
	}
	ll tot=1;for(int i=1;i<=n;i++) tot=tot*(i*2-1)%p;
	printf("%lld\n",(tot-f[n][0]+p)%p);
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

詳細信息

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 1ms
memory: 4008kb

input:

1 194903119

output:

0

result:

ok 1 number(s): "0"

Test #2:

score: 0
Accepted
time: 0ms
memory: 4004kb

input:

2 933234047

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 0ms
memory: 4000kb

input:

3 277793111

output:

2

result:

ok 1 number(s): "2"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3956kb

input:

4 355321177

output:

28

result:

ok 1 number(s): "28"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3956kb

input:

5 306636893

output:

358

result:

ok 1 number(s): "358"

Subtask #2:

score: 5
Accepted

Dependency #1:

100%
Accepted

Test #6:

score: 5
Accepted
time: 0ms
memory: 4036kb

input:

8 361605653

output:

1236922

result:

ok 1 number(s): "1236922"

Test #7:

score: 0
Accepted
time: 0ms
memory: 4008kb

input:

8 995512643

output:

1236922

result:

ok 1 number(s): "1236922"

Test #8:

score: 0
Accepted
time: 0ms
memory: 4016kb

input:

8 101102801

output:

1236922

result:

ok 1 number(s): "1236922"

Test #9:

score: 0
Accepted
time: 0ms
memory: 4016kb

input:

6 458322727

output:

4894

result:

ok 1 number(s): "4894"

Test #10:

score: 0
Accepted
time: 0ms
memory: 4032kb

input:

7 721691819

output:

73884

result:

ok 1 number(s): "73884"

Test #11:

score: 0
Accepted
time: 0ms
memory: 3944kb

input:

7 370629137

output:

73884

result:

ok 1 number(s): "73884"

Subtask #3:

score: 27
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Test #12:

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

input:

30 779092367

output:

686412377

result:

ok 1 number(s): "686412377"

Test #13:

score: 0
Accepted
time: 0ms
memory: 4012kb

input:

29 963995171

output:

128570082

result:

ok 1 number(s): "128570082"

Test #14:

score: 0
Accepted
time: 0ms
memory: 3968kb

input:

18 666092701

output:

185922458

result:

ok 1 number(s): "185922458"

Test #15:

score: 0
Accepted
time: 0ms
memory: 4032kb

input:

14 671243719

output:

623913899

result:

ok 1 number(s): "623913899"

Subtask #4:

score: 14
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Test #16:

score: 14
Accepted
time: 1ms
memory: 4000kb

input:

300 463478027

output:

89265245

result:

ok 1 number(s): "89265245"

Test #17:

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

input:

296 567610679

output:

406342763

result:

ok 1 number(s): "406342763"

Test #18:

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

input:

297 609090359

output:

128986577

result:

ok 1 number(s): "128986577"

Test #19:

score: 0
Accepted
time: 0ms
memory: 3884kb

input:

48 759569383

output:

635573072

result:

ok 1 number(s): "635573072"

Test #20:

score: 0
Accepted
time: 0ms
memory: 4052kb

input:

99 298873033

output:

285340078

result:

ok 1 number(s): "285340078"

Subtask #5:

score: 36
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Test #21:

score: 36
Accepted
time: 65ms
memory: 4092kb

input:

3000 752129633

output:

33058561

result:

ok 1 number(s): "33058561"

Test #22:

score: 0
Accepted
time: 65ms
memory: 4136kb

input:

2993 491173567

output:

343277625

result:

ok 1 number(s): "343277625"

Test #23:

score: 0
Accepted
time: 65ms
memory: 4168kb

input:

2993 783095563

output:

776085006

result:

ok 1 number(s): "776085006"

Test #24:

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

input:

327 399783431

output:

163535283

result:

ok 1 number(s): "163535283"

Test #25:

score: 0
Accepted
time: 12ms
memory: 4080kb

input:

1233 857060207

output:

422139845

result:

ok 1 number(s): "422139845"

Test #26:

score: 0
Accepted
time: 9ms
memory: 4048kb

input:

1114 600227447

output:

598509129

result:

ok 1 number(s): "598509129"

Subtask #6:

score: 13
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Test #27:

score: 13
Accepted
time: 2874ms
memory: 4940kb

input:

20000 221054167

output:

39809956

result:

ok 1 number(s): "39809956"

Test #28:

score: 0
Accepted
time: 2871ms
memory: 4932kb

input:

19997 823974001

output:

267537750

result:

ok 1 number(s): "267537750"

Test #29:

score: 0
Accepted
time: 2866ms
memory: 4924kb

input:

19991 501689843

output:

16527909

result:

ok 1 number(s): "16527909"

Test #30:

score: 0
Accepted
time: 1474ms
memory: 4640kb

input:

14344 925452091

output:

212324779

result:

ok 1 number(s): "212324779"

Test #31:

score: 0
Accepted
time: 264ms
memory: 4316kb

input:

6098 507350869

output:

310480789

result:

ok 1 number(s): "310480789"

Test #32:

score: 0
Accepted
time: 219ms
memory: 4256kb

input:

5564 406069759

output:

105694337

result:

ok 1 number(s): "105694337"

Extra Test:

score: 0
Extra Test Passed