QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#104412#6333. Festivals in JOI Kingdom 2oscaryang87 279ms10460kbC++201.3kb2023-05-10 17:13:032023-05-10 17:13:05

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-10 17:13:05]
  • 评测
  • 测评结果:87
  • 用时:279ms
  • 内存:10460kb
  • [2023-05-10 17:13:03]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=4e5+5;

int n,P,fc[N],ifc[N];
int o,w,f[2][N][3],ad[N][3],ans,all;

//calc
inline void inc(int &x,int y) { x+=y-P; x+=(x>>31)&P; }
inline void dec(int &x,int y) { x-=y; x+=(x>>31)&P; }
inline int pls(int x,int y) { return x+=y-P, x+=(x>>31)&P, x; }
inline int power(int a,int b) { int res=1; for(;b;b>>=1,a=1ll*a*a%P) if(b&1) res=1ll*res*a%P; return res; }

int main() {
	cin>>n>>P;
	
	fc[0]=ifc[0]=all=1; 
	for(int i=1;i<N;i++) fc[i]=1ll*i*fc[i-1]%P;
	ifc[N-1]=power(fc[N-1],P-2);
	for(int i=N-2;i>=1;i--) ifc[i]=1ll*ifc[i+1]*(i+1)%P;
	
	int *F, m=2*n; o=0; w=1; f[o][0][0]=1; 
	for(int i=0,up;i<=m;i++,swap(o,w)) {
		for(int j=0;j<3;j++) inc(f[o][0][j],ad[i][j]);
		if(i==m) break; 
		up=min(m-i+1,i);
		for(int k=0;k<=up;k++) {
			F = f[o][k];
			if(F[0]) inc(f[w][k+1][1],F[0]);
			if(F[1]) {
				inc(f[w][k+1][1],F[1]);
				if(k && i+k<=m) inc(ad[i+k][0],1ll*F[1]*fc[m-i-1]%P*ifc[m-i-k]%P);
				if(k>1 && i+k<=m) inc(ad[i+k-1][2],1ll*F[1]*(k-1)%P*fc[m-i-1]%P*ifc[m-i-k+1]%P);
			}
			if(F[2]) {
				inc(f[w][k+1][2],F[2]);
				inc(f[w][k][0],F[2]);
			}
			F[0]=F[1]=F[2]=0;
		}
	}
	
	for(int i=1;i<=m;i+=2) all=1ll*all*i%P;
	dec(ans=all,f[o][0][0]);
	cout<<ans<<endl;
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 14ms
memory: 8752kb

input:

1 194903119

output:

0

result:

ok 1 number(s): "0"

Test #2:

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

input:

2 933234047

output:

0

result:

ok 1 number(s): "0"

Test #3:

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

input:

3 277793111

output:

2

result:

ok 1 number(s): "2"

Test #4:

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

input:

4 355321177

output:

28

result:

ok 1 number(s): "28"

Test #5:

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

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: 13ms
memory: 7568kb

input:

8 361605653

output:

1236922

result:

ok 1 number(s): "1236922"

Test #7:

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

input:

8 995512643

output:

1236922

result:

ok 1 number(s): "1236922"

Test #8:

score: 0
Accepted
time: 13ms
memory: 7496kb

input:

8 101102801

output:

1236922

result:

ok 1 number(s): "1236922"

Test #9:

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

input:

6 458322727

output:

4894

result:

ok 1 number(s): "4894"

Test #10:

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

input:

7 721691819

output:

73884

result:

ok 1 number(s): "73884"

Test #11:

score: 0
Accepted
time: 10ms
memory: 7960kb

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: 14ms
memory: 10460kb

input:

30 779092367

output:

686412377

result:

ok 1 number(s): "686412377"

Test #13:

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

input:

29 963995171

output:

128570082

result:

ok 1 number(s): "128570082"

Test #14:

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

input:

18 666092701

output:

185922458

result:

ok 1 number(s): "185922458"

Test #15:

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

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: 9ms
memory: 9464kb

input:

300 463478027

output:

89265245

result:

ok 1 number(s): "89265245"

Test #17:

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

input:

296 567610679

output:

406342763

result:

ok 1 number(s): "406342763"

Test #18:

score: 0
Accepted
time: 17ms
memory: 8320kb

input:

297 609090359

output:

128986577

result:

ok 1 number(s): "128986577"

Test #19:

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

input:

48 759569383

output:

635573072

result:

ok 1 number(s): "635573072"

Test #20:

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

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: 279ms
memory: 8108kb

input:

3000 752129633

output:

33058561

result:

ok 1 number(s): "33058561"

Test #22:

score: 0
Accepted
time: 253ms
memory: 6872kb

input:

2993 491173567

output:

343277625

result:

ok 1 number(s): "343277625"

Test #23:

score: 0
Accepted
time: 263ms
memory: 7532kb

input:

2993 783095563

output:

776085006

result:

ok 1 number(s): "776085006"

Test #24:

score: 0
Accepted
time: 17ms
memory: 7504kb

input:

327 399783431

output:

163535283

result:

ok 1 number(s): "163535283"

Test #25:

score: 0
Accepted
time: 56ms
memory: 8132kb

input:

1233 857060207

output:

422139845

result:

ok 1 number(s): "422139845"

Test #26:

score: 0
Accepted
time: 37ms
memory: 9264kb

input:

1114 600227447

output:

598509129

result:

ok 1 number(s): "598509129"

Subtask #6:

score: 0
Time Limit Exceeded

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Test #27:

score: 0
Time Limit Exceeded

input:

20000 221054167

output:


result: