QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#619392#8635. 圆Daniel777100 ✓470ms4072kbC++141.6kb2024-10-07 14:04:402024-10-07 14:04:40

Judging History

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

  • [2024-10-07 14:04:40]
  • 评测
  • 测评结果:100
  • 用时:470ms
  • 内存:4072kb
  • [2024-10-07 14:04:40]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5005,mod = 998244353;
int f[2][N][3][3],n,ans[N];
int now,lst = 1;
ll inv[N],Sum;
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    cin>>n;
    f[now][0][0][0] = f[now][0][2][2] = mod-1;
    f[now][0][1][0] = f[now][0][0][1] = 1;
    for(int i = 3;i <= n;i++)
    {
        swap(now,lst);
        memset(f[now],0,sizeof(f[now]));
        for(int j = 0;j <= i-3;j++)
        {
            for(int x = 0;x < 3;x++)
            {
                for(int y = 0;y < 3;y++)
                {
                    f[now][j+(y==2)][x][y+(y!=2)] = (f[now][j+(y==2)][x][y+(y!=2)] + f[lst][j][x][y])%mod;
                    f[now][j][x][0] = (f[now][j][x][0] + mod - f[lst][j][x][y])%mod;//这里容斥掉
                }
            }
        }
    }
    for(int j = 0;j <= n-2;j++)
        for(int x = 0;x < 3;x++)
            for(int y = 0;y < 3;y++)
            {
                if(x + y >= 3) ans[j+x+y-2] = (ans[j+x+y-2] + f[now][j][x][y])%mod;
                else ans[j] = (ans[j] + f[now][j][x][y])%mod;
            }
    ans[n] = 0;
    inv[1] = 1;
    for(int i = 2;i <= n;i++) inv[i] = mod - mod/i*inv[mod%i]%mod;
    for(int i = 0;i < n;i++)
    {
        //cout<<i<<" "<<ans[i]<<"\n";
        ll res = 1,tmp = 1;
        for(int j = 0;j < i;j++)
        {
            tmp = tmp*(i-j)%mod*inv[n-j]%mod;
            res = (res + tmp)%mod;
        }
        //cout<<res<<"\n";
        Sum = (Sum + ans[i]*res)%mod;
    }
    cout<<Sum<<"\n";
    return 0;
}

详细


Pretests


Final Tests

Test #1:

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

input:

3

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 10
Accepted
time: 1ms
memory: 3916kb

input:

4

output:

2

result:

ok 1 number(s): "2"

Test #3:

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

input:

6

output:

299473309

result:

ok 1 number(s): "299473309"

Test #4:

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

input:

10

output:

487238321

result:

ok 1 number(s): "487238321"

Test #5:

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

input:

100

output:

41620761

result:

ok 1 number(s): "41620761"

Test #6:

score: 10
Accepted
time: 2ms
memory: 3924kb

input:

200

output:

208771764

result:

ok 1 number(s): "208771764"

Test #7:

score: 10
Accepted
time: 6ms
memory: 4000kb

input:

500

output:

888621375

result:

ok 1 number(s): "888621375"

Test #8:

score: 10
Accepted
time: 430ms
memory: 4072kb

input:

4798

output:

319137015

result:

ok 1 number(s): "319137015"

Test #9:

score: 10
Accepted
time: 466ms
memory: 3964kb

input:

4999

output:

818467659

result:

ok 1 number(s): "818467659"

Test #10:

score: 10
Accepted
time: 470ms
memory: 3984kb

input:

5000

output:

142907477

result:

ok 1 number(s): "142907477"