QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#482138#9121. I Love Marathon ContestCrysflyAC ✓440ms29440kbC++174.0kb2024-07-17 17:32:552024-07-17 17:32:55

Judging History

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

  • [2024-07-17 17:32:55]
  • 评测
  • 测评结果:AC
  • 用时:440ms
  • 内存:29440kb
  • [2024-07-17 17:32:55]
  • 提交

answer

// what is matter? never mind. 
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2") 
#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
//#define int long long
#define ull unsigned long long
#define SZ(x) ((int)((x).size()))
#define ALL(x) (x).begin(),(x).end()
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;
}

#define mod 998244353
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=1ll*x*o.x%mod,*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,modint b){return a.x==b.x;}
	friend bool operator !=(modint a,modint b){return a.x!=b.x;}
	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;}

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 200005
#define inf 0x3f3f3f3f

int n;
int b[maxn],bb[maxn];
modint res=0;

int cnt1,cnt0;
int sum[maxn];

int br(){
	For(i,1,n*2)bb[i]=b[i];
	int u=0,res=0,now=-1,cnt=n*2;
	while(1){
		if(u==n*2) u=1,++res;
		else ++u;
		if(cnt==0 && u==1) break;
		if(b[u]==-now){
			b[u]=0,now=-now;
			--cnt;
		}
	//	For(i,1,n*2)cout<<b[i]<<" "; cout<<"\n";
	}
//	cout<<res<<"\n";
	For(i,1,n*2)b[i]=bb[i];
	return res;
}
void chk(){
	
	int mx=0,mn=0;
	For(i,1,n*2){
		sum[i]=sum[i-1]+b[i];
		mx=max(mx,sum[i]),mn=min(mn,sum[i]);
	}
	
//	For(i,1,n*2) cout<<b[i]<<" "; cout<<"\n";
	
	int ans=mx-mn;
	{
		bool ok=0;
		Rep(i,n*2,0){
			if(sum[i]==mn){
				ok=0;
				break;
			}
			if(sum[i]==mx){
				ok=1;
				break;
			}
		}
		cnt1+=ok; cnt0+=(!ok);
		ans+=ok;
	}
	
//	cout<<ans<<" "; cout<<"\n";
//	int tmp=br();
//	if(tmp!=ans)exit(2343);
	
	res+=ans;
//	if(mn<0)res+=1;
}
void dfs(int u,int u1,int u2){
	if(u==2*n+1){
		chk();
		return;
	}
	if(u1) b[u]=1,dfs(u+1,u1-1,u2);
	if(u2 && u>1) b[u]=-1,dfs(u+1,u1,u2-1);
}

modint divsum[maxn];
modint S(int n,int a){
	modint res=0;
	For(k,1,a+n)
		res+=divsum[k]*C(n*2,n+a-k);
	res/=C(n*2,n);
	return res;
}

signed main()
{
	n=read(); initC(n*2);
	
//	For(i,1,n*2)
//		for(int j=i;j<=n*2;j+=i) divsum[j]+=1;
	
	modint res=0;
	res+=C(2*n-1,n-1);
	For(i,1,n-1) res+=C(2*n-1,n+i);
	
	For(i,1,n-1) res+=2*C(2*n-2,n-1-i);
	
//	modint tmp=((n+1)*S(n,1)-2*S(n,0)+S(n,-1))-1;
//	tmp*=C(n*2,n)*iv[n+1];
//	res-=tmp;

	For(i,1,n-1) For(k,1,n/(i+1)) {
		res-=C(2*n-2,n-k*(i+1));
		res+=2*C(2*n-2,n-1-k*(i+1));
		res-=C(2*n-2,n-2-k*(i+1));
	}
	
	res*=2,res*=fac[n]*fac[n];
	cout<<res.x;
	return 0;
}
/*

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 4596kb

input:

1

output:

2

result:

ok "2"

Test #2:

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

input:

2

output:

40

result:

ok "40"

Test #3:

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

input:

3

output:

1656

result:

ok "1656"

Test #4:

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

input:

4

output:

112896

result:

ok "112896"

Test #5:

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

input:

5

output:

11750400

result:

ok "11750400"

Test #6:

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

input:

6

output:

741506047

result:

ok "741506047"

Test #7:

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

input:

7

output:

663688356

result:

ok "663688356"

Test #8:

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

input:

8

output:

564862407

result:

ok "564862407"

Test #9:

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

input:

9

output:

161774290

result:

ok "161774290"

Test #10:

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

input:

10

output:

652045233

result:

ok "652045233"

Test #11:

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

input:

11

output:

748014862

result:

ok "748014862"

Test #12:

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

input:

12

output:

304641307

result:

ok "304641307"

Test #13:

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

input:

13

output:

729875009

result:

ok "729875009"

Test #14:

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

input:

14

output:

711836922

result:

ok "711836922"

Test #15:

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

input:

15

output:

920550523

result:

ok "920550523"

Test #16:

score: 0
Accepted
time: 6ms
memory: 6580kb

input:

17408

output:

632438437

result:

ok "632438437"

Test #17:

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

input:

46789

output:

458137544

result:

ok "458137544"

Test #18:

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

input:

22610

output:

356200349

result:

ok "356200349"

Test #19:

score: 0
Accepted
time: 7ms
memory: 4576kb

input:

33916

output:

52946419

result:

ok "52946419"

Test #20:

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

input:

37395

output:

66208794

result:

ok "66208794"

Test #21:

score: 0
Accepted
time: 233ms
memory: 18344kb

input:

564256

output:

145325890

result:

ok "145325890"

Test #22:

score: 0
Accepted
time: 346ms
memory: 23428kb

input:

834557

output:

942727699

result:

ok "942727699"

Test #23:

score: 0
Accepted
time: 288ms
memory: 20324kb

input:

700474

output:

110750834

result:

ok "110750834"

Test #24:

score: 0
Accepted
time: 214ms
memory: 16244kb

input:

530345

output:

407205453

result:

ok "407205453"

Test #25:

score: 0
Accepted
time: 399ms
memory: 26000kb

input:

942062

output:

849740307

result:

ok "849740307"

Test #26:

score: 0
Accepted
time: 256ms
memory: 18608kb

input:

629156

output:

521070781

result:

ok "521070781"

Test #27:

score: 0
Accepted
time: 363ms
memory: 24000kb

input:

861230

output:

52253753

result:

ok "52253753"

Test #28:

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

input:

643760

output:

896717464

result:

ok "896717464"

Test #29:

score: 0
Accepted
time: 371ms
memory: 24428kb

input:

877036

output:

148107554

result:

ok "148107554"

Test #30:

score: 0
Accepted
time: 291ms
memory: 19744kb

input:

672739

output:

384285823

result:

ok "384285823"

Test #31:

score: 0
Accepted
time: 427ms
memory: 28512kb

input:

999991

output:

11040806

result:

ok "11040806"

Test #32:

score: 0
Accepted
time: 425ms
memory: 27260kb

input:

999992

output:

10247994

result:

ok "10247994"

Test #33:

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

input:

999993

output:

288885449

result:

ok "288885449"

Test #34:

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

input:

999994

output:

488915584

result:

ok "488915584"

Test #35:

score: 0
Accepted
time: 423ms
memory: 29436kb

input:

999995

output:

913096398

result:

ok "913096398"

Test #36:

score: 0
Accepted
time: 430ms
memory: 29440kb

input:

999996

output:

125855903

result:

ok "125855903"

Test #37:

score: 0
Accepted
time: 423ms
memory: 27316kb

input:

999997

output:

616335312

result:

ok "616335312"

Test #38:

score: 0
Accepted
time: 425ms
memory: 29336kb

input:

999998

output:

381708275

result:

ok "381708275"

Test #39:

score: 0
Accepted
time: 422ms
memory: 27236kb

input:

999999

output:

513037643

result:

ok "513037643"

Test #40:

score: 0
Accepted
time: 425ms
memory: 29372kb

input:

1000000

output:

252793281

result:

ok "252793281"

Extra Test:

score: 0
Extra Test Passed