QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#619580#8635. 圆hjxhjx100 ✓18ms100904kbC++141.1kb2024-10-07 14:42:132024-10-07 14:42:14

Judging History

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

  • [2024-10-07 14:42:14]
  • 评测
  • 测评结果:100
  • 用时:18ms
  • 内存:100904kb
  • [2024-10-07 14:42:13]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

inline static int read(){
    int sum=0,neg=0,ch=getchar();
    while(!isdigit(ch)) neg|=(ch=='-'),ch=getchar();
    while(isdigit(ch)) sum=sum*10+(ch^48),ch=getchar();
    return neg?-sum:sum;
}
constexpr int mod=998244353;
int dp[5005][5005],fac[5005],inv[5005];
int power(ll a,int b){
    ll ret=1;
    while(b){
        if(b&1) ret=ret*a%mod;
        a=a*a%mod,b>>=1;
    } return ret;
}
signed main(){
    // freopen("color.in","r",stdin);
    // freopen("color.out","w",stdout);
    int n=read(),ans=0; **dp=*fac=*inv=1;
    for(int i=1;i<=n;i++) fac[i]=(ll)fac[i-1]*i%mod; inv[n]=power(fac[n],mod-2);
    for(int i=n-1;i;i--) inv[i]=(ll)inv[i+1]*(n-i)%mod;
    for(int i=3;i<=n;i++) for(int j=0;j<i;j++)
        dp[i][j+1]=((ll)dp[i-1][j]+dp[i-2][j]+dp[i-3][j])%mod;
    for(int _=1,t=n-1;_<=3;_++,t--) for(int i=0;i<=t;i++)
        ans=(ans+(4ll-_)*i*dp[t][i]%mod*fac[i]%mod*inv[i+1])%mod;
    return printf("%lld\n",((ll)ans*n+1)%mod),0;
}

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

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

input:

3

output:

1

result:

ok 1 number(s): "1"

Test #2:

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

input:

4

output:

2

result:

ok 1 number(s): "2"

Test #3:

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

input:

6

output:

299473309

result:

ok 1 number(s): "299473309"

Test #4:

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

input:

10

output:

487238321

result:

ok 1 number(s): "487238321"

Test #5:

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

input:

100

output:

41620761

result:

ok 1 number(s): "41620761"

Test #6:

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

input:

200

output:

208771764

result:

ok 1 number(s): "208771764"

Test #7:

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

input:

500

output:

888621375

result:

ok 1 number(s): "888621375"

Test #8:

score: 10
Accepted
time: 13ms
memory: 96408kb

input:

4798

output:

319137015

result:

ok 1 number(s): "319137015"

Test #9:

score: 10
Accepted
time: 18ms
memory: 100904kb

input:

4999

output:

818467659

result:

ok 1 number(s): "818467659"

Test #10:

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

input:

5000

output:

142907477

result:

ok 1 number(s): "142907477"