QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#426874#8635. 圆Kevin5307100 ✓60ms305812kbC++231.5kb2024-05-31 23:41:492024-05-31 23:41:50

Judging History

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

  • [2024-05-31 23:41:50]
  • 评测
  • 测评结果:100
  • 用时:60ms
  • 内存:305812kb
  • [2024-05-31 23:41:49]
  • 提交

answer

//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
const ll mod=998244353;
ll ksm(ll a,ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1) ans=ans*a%mod;
		b>>=1;
		a=a*a%mod;
	}
	return ans;
}
ll C[5005][5005];
ll dp[5005][5005];
void upd(ll &a,ll b){a=(a+b)%mod;}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	for(int i=0;i<5005;i++)
		C[i][i]=C[i][0]=1;
	for(int i=2;i<5005;i++)
		for(int j=1;j<i;j++)
			C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
	int n;
	cin>>n;
	if(n<=3) die("1");
	dp[1][1]=1;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=i;j++)
		{
			upd(dp[i+1][j+1],dp[i][j]);
			upd(dp[i+2][j+1],dp[i][j]);
			upd(dp[i+3][j+1],dp[i][j]);
		}
	ll ans=0;
	for(int i=1;i<=n;i++)
	{
		ll tot=0;
		upd(tot,dp[n][i]);
		upd(tot,dp[n-1][i]);
		upd(tot,dp[n-2][i]);
		ll Tot=C[n-1][i-1];
		upd(ans,(Tot-tot+mod)*ksm(Tot,mod-2));
	}
	cout<<(ans+1)%mod<<endl;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 10
Accepted
time: 12ms
memory: 183868kb

input:

3

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 10
Accepted
time: 24ms
memory: 187040kb

input:

4

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: 10
Accepted
time: 23ms
memory: 187300kb

input:

6

output:

299473309

result:

ok 1 number(s): "299473309"

Test #4:

score: 10
Accepted
time: 16ms
memory: 190516kb

input:

10

output:

487238321

result:

ok 1 number(s): "487238321"

Test #5:

score: 10
Accepted
time: 23ms
memory: 190756kb

input:

100

output:

41620761

result:

ok 1 number(s): "41620761"

Test #6:

score: 10
Accepted
time: 19ms
memory: 191284kb

input:

200

output:

208771764

result:

ok 1 number(s): "208771764"

Test #7:

score: 10
Accepted
time: 12ms
memory: 193120kb

input:

500

output:

888621375

result:

ok 1 number(s): "888621375"

Test #8:

score: 10
Accepted
time: 47ms
memory: 299168kb

input:

4798

output:

319137015

result:

ok 1 number(s): "319137015"

Test #9:

score: 10
Accepted
time: 60ms
memory: 305496kb

input:

4999

output:

818467659

result:

ok 1 number(s): "818467659"

Test #10:

score: 10
Accepted
time: 47ms
memory: 305812kb

input:

5000

output:

142907477

result:

ok 1 number(s): "142907477"