QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#99259#6333. Festivals in JOI Kingdom 2Crysfly100 ✓3424ms4756kbC++173.3kb2023-04-21 19:15:062023-04-21 19:15:07

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-21 19:15:07]
  • 评测
  • 测评结果:100
  • 用时:3424ms
  • 内存:4756kb
  • [2023-04-21 19:15:06]
  • 提交

answer

#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
using namespace std;
inline int read()
{
	char c=getchar();int x=0;bool f=0;
	for(;!isdigit(c);c=getchar())f^=!(c^45);
	for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
	if(f)x=-x;return x;
}

int mod;
typedef unsigned long long ull;
namespace FM{
	typedef __uint128_t L;
	struct FastMod{
		ull b,m;
		FastMod(ull b):b(b),m(ull((L(1)<<64)/b)){}
		ull reduce(ull a){ull q=(ull)((L(m)*a)>>64),r=a-q*b;return r>=b?r-b:r;}
	};
	FastMod F(2);
}

struct modint{
	int x;
	modint(int o=0){x=o;}
	modint &operator = (int o){return x=o,*this;}
	modint &operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}
	modint &operator -=(modint o){return x=x-o.x<0?x-o.x+mod:x-o.x,*this;}
	modint &operator *=(modint o){return x=FM::F.reduce(1ull*x*o.x),*this;}
	modint &operator ^=(int b){
		modint a=*this,c=1;
		for(;b;b>>=1,a*=a)if(b&1)c*=a;
		return x=c.x,*this;
	}
	modint &operator /=(modint o){return *this *=o^=mod-2;}
	friend modint operator +(modint a,modint b){return a+=b;}
	friend modint operator -(modint a,modint b){return a-=b;}
	friend modint operator *(modint a,modint b){return a*=b;}
	friend modint operator /(modint a,modint b){return a/=b;}
	friend modint operator ^(modint a,int b){return a^=b;}
	friend bool operator ==(modint a,int b){return a.x==b;}
	friend bool operator !=(modint a,int b){return a.x!=b;}
	bool operator ! () {return !x;}
	modint operator - () {return x?mod-x:0;}
	bool operator <(const modint&b)const{return x<b.x;}
};
inline modint qpow(modint x,int y){return x^y;}
void initmod(){mod=read(),FM::F=FM::FastMod(mod);}

vector<modint> fac,ifac,iv;
inline void initC(int n)
{
	if(iv.empty())fac=ifac=iv=vector<modint>(2,1);
	int m=iv.size(); ++n;
	if(m>=n)return;
	iv.resize(n),fac.resize(n),ifac.resize(n);
	For(i,m,n-1){
		iv[i]=iv[mod%i]*(mod-mod/i);
		fac[i]=fac[i-1]*i,ifac[i]=ifac[i-1]*iv[i];
	}
}
inline modint C(int n,int m){
	if(m<0||n<m)return 0;
	return initC(n),fac[n]*ifac[m]*ifac[n-m];
}
inline modint sign(int n){return (n&1)?(mod-1):(1);}

#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi; 

#define maxn 300005
#define inf 0x3f3f3f3f
#define ll long long 

int n;

modint f[20005][3],g[20005][3],tmp[40005][2]; 
modint prod(int m,int n){
	return fac[n]*ifac[m-1];
}

signed main()
{
	n=read(); initmod(); initC(n*4);
	f[0][2]=1;
	/*
	0 : bad 无可取的线头 
	1 : bad 少了 1 且 bad 有可取的线头
	2 : bad 有可取的线头
	*/
	For(i,2,n*2){
		int mx=min(n*2-i+1,i);
		For(j,0,mx){
			if(f[j][0].x){
				g[j][2]+=f[j][0];
			}
			if(f[j][2].x){
				g[j+1][2]+=f[j][2];
				if(i+j<=n*2) tmp[i+j][0]+=f[j][2]*fac[2*n-i]*ifac[2*n-i-j];
				if(j && i+j<=n*2) tmp[i+j-1][1]+=f[j][2]*j*fac[2*n-i]*ifac[2*n-i-j+1];
			}
			if(f[j][1].x){
				g[j+1][1]+=f[j][1];
				g[j][0]+=f[j][1];
			}
		}
		mx=min(n*2-(i+1)+1,i+1);
		For(c,0,1) g[0][c]+=tmp[i][c];
		For(j,0,mx) For(c,0,2) f[j][c]=g[j][c],g[j][c]=0;
	}
	modint res=f[0][0];
	modint mul=1;
	for(int i=n*2-1;i>=1;i-=2)mul*=i;
//	cout<<res.x<<'\n';
	cout<<(mul-res).x<<"\n";
	return 0;
}

詳細信息

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 3ms
memory: 4220kb

input:

1 194903119

output:

0

result:

ok 1 number(s): "0"

Test #2:

score: 0
Accepted
time: 2ms
memory: 4156kb

input:

2 933234047

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 3ms
memory: 4068kb

input:

3 277793111

output:

2

result:

ok 1 number(s): "2"

Test #4:

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

input:

4 355321177

output:

28

result:

ok 1 number(s): "28"

Test #5:

score: 0
Accepted
time: 2ms
memory: 4084kb

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: 2ms
memory: 4104kb

input:

8 361605653

output:

1236922

result:

ok 1 number(s): "1236922"

Test #7:

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

input:

8 995512643

output:

1236922

result:

ok 1 number(s): "1236922"

Test #8:

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

input:

8 101102801

output:

1236922

result:

ok 1 number(s): "1236922"

Test #9:

score: 0
Accepted
time: 2ms
memory: 4176kb

input:

6 458322727

output:

4894

result:

ok 1 number(s): "4894"

Test #10:

score: 0
Accepted
time: 2ms
memory: 4116kb

input:

7 721691819

output:

73884

result:

ok 1 number(s): "73884"

Test #11:

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

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: 1ms
memory: 4104kb

input:

30 779092367

output:

686412377

result:

ok 1 number(s): "686412377"

Test #13:

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

input:

29 963995171

output:

128570082

result:

ok 1 number(s): "128570082"

Test #14:

score: 0
Accepted
time: 3ms
memory: 4064kb

input:

18 666092701

output:

185922458

result:

ok 1 number(s): "185922458"

Test #15:

score: 0
Accepted
time: 3ms
memory: 4072kb

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

input:

300 463478027

output:

89265245

result:

ok 1 number(s): "89265245"

Test #17:

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

input:

296 567610679

output:

406342763

result:

ok 1 number(s): "406342763"

Test #18:

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

input:

297 609090359

output:

128986577

result:

ok 1 number(s): "128986577"

Test #19:

score: 0
Accepted
time: 3ms
memory: 4144kb

input:

48 759569383

output:

635573072

result:

ok 1 number(s): "635573072"

Test #20:

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

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: 76ms
memory: 4364kb

input:

3000 752129633

output:

33058561

result:

ok 1 number(s): "33058561"

Test #22:

score: 0
Accepted
time: 71ms
memory: 4240kb

input:

2993 491173567

output:

343277625

result:

ok 1 number(s): "343277625"

Test #23:

score: 0
Accepted
time: 79ms
memory: 4280kb

input:

2993 783095563

output:

776085006

result:

ok 1 number(s): "776085006"

Test #24:

score: 0
Accepted
time: 4ms
memory: 4088kb

input:

327 399783431

output:

163535283

result:

ok 1 number(s): "163535283"

Test #25:

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

input:

1233 857060207

output:

422139845

result:

ok 1 number(s): "422139845"

Test #26:

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

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: 3424ms
memory: 4704kb

input:

20000 221054167

output:

39809956

result:

ok 1 number(s): "39809956"

Test #28:

score: 0
Accepted
time: 3420ms
memory: 4736kb

input:

19997 823974001

output:

267537750

result:

ok 1 number(s): "267537750"

Test #29:

score: 0
Accepted
time: 3408ms
memory: 4756kb

input:

19991 501689843

output:

16527909

result:

ok 1 number(s): "16527909"

Test #30:

score: 0
Accepted
time: 1793ms
memory: 4488kb

input:

14344 925452091

output:

212324779

result:

ok 1 number(s): "212324779"

Test #31:

score: 0
Accepted
time: 318ms
memory: 4396kb

input:

6098 507350869

output:

310480789

result:

ok 1 number(s): "310480789"

Test #32:

score: 0
Accepted
time: 261ms
memory: 4396kb

input:

5564 406069759

output:

105694337

result:

ok 1 number(s): "105694337"

Extra Test:

score: 0
Extra Test Passed