QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#235121#6333. Festivals in JOI Kingdom 2275307894a#10 1ms3984kbC++141.3kb2023-11-02 14:34:342024-07-04 02:22:38

Judging History

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

  • [2024-07-04 02:22:38]
  • 评测
  • 测评结果:10
  • 用时:1ms
  • 内存:3984kb
  • [2023-11-02 14:34:34]
  • 提交

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=600+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],inv[N];
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++){
			f[i][0]+=calc(2*i-1-j,j-1)*f[i-j][0]%p;
			if(j>1) f[i][0]+=(j-1)*calc(2*i-1-j,j-2)%p*f[i-j][1]%p;
		}
		f[i][0]%=p;
		for(j=1;j<=i;j++){
			f[i][1]+=j*calc(2*i-1-j,j-1)%p*f[i-j][0]%p;
			if(j>1) f[i][1]+=j*(j-1)%p*calc(2*i-1-j,j-2)%p*f[i-j][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);
}

詳細信息

Subtask #1:

score: 5
Accepted

Test #1:

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

input:

1 194903119

output:

0

result:

ok 1 number(s): "0"

Test #2:

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

input:

2 933234047

output:

0

result:

ok 1 number(s): "0"

Test #3:

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

input:

3 277793111

output:

2

result:

ok 1 number(s): "2"

Test #4:

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

input:

4 355321177

output:

28

result:

ok 1 number(s): "28"

Test #5:

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

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: 3848kb

input:

8 361605653

output:

1236922

result:

ok 1 number(s): "1236922"

Test #7:

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

input:

8 995512643

output:

1236922

result:

ok 1 number(s): "1236922"

Test #8:

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

input:

8 101102801

output:

1236922

result:

ok 1 number(s): "1236922"

Test #9:

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

input:

6 458322727

output:

4894

result:

ok 1 number(s): "4894"

Test #10:

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

input:

7 721691819

output:

73884

result:

ok 1 number(s): "73884"

Test #11:

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

input:

7 370629137

output:

73884

result:

ok 1 number(s): "73884"

Subtask #3:

score: 0
Wrong Answer

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Test #12:

score: 0
Wrong Answer
time: 1ms
memory: 3980kb

input:

30 779092367

output:

154635340

result:

wrong answer 1st numbers differ - expected: '686412377', found: '154635340'

Subtask #4:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

0%