QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#232931#6410. Classical DP Problembrianabucur10WA 1ms5756kbC++141.5kb2023-10-31 01:23:052023-10-31 01:23:05

Judging History

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

  • [2023-10-31 01:23:05]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5756kb
  • [2023-10-31 01:23:05]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

int n, v[5005], a[5005], dp1[5005][5005], dp2[5005][5005], t, k;

long long fact (int n)
{
    int p=1;
    for (int i=2; i<=n; i++)
    {
        p*=i;
        p%=998244353;
    }
    return p%998244353;
}

void pd (int v[], int dp[][5005])
{
    int x=v[k+1];
    dp[0][x]=1;
    for (int i=0; i<=k; i++)
    {
        for (int j=0; j<=v[i+1] && j<=x; j++)
        {
            dp[i+1][j]+=(1LL*(v[i+1]-j)*dp[i][j]%998244353);
            dp[i+1][j]%=998244353;
            if (j>0)
            {
                dp[i+1][j-1]+=(1LL*j*dp[i][j]%998244353);
                dp[i+1][j-1]%=998244353;
            }
        }
    }
}

void rotire ()
{
    for (int i=1; i<=n; i++)
    {
        for (int j=1; j<=n; j++)
        {
            if (v[j]>=i)
                a[i]++;
            else
                break;
        }
    }
}

int main()
{
    //9 1 1 2 5 6 6 6 7 9
    cin >> n;
    for (int i=1; i<=n; i++)
        cin >> v[n-i+1];
    for (int i=1; i<=n; i++)
    {
        bool ok=true;
        for (int j=1; j<=i; j++)
        {
            if (v[j]<i)
                ok=false;
        }
        if (!ok)
            break;
        else
            k=i;
    }
    rotire();
    pd(v,dp1);
    pd(a,dp2);
    //cout << dp1[k][0] << " " << dp2[k][0];
    long long rez=(dp1[k][0]%998244353+dp2[k][0]%998244353-1LL*fact(k)%998244353)%998244353;
    cout << k << " " << 1LL*rez%998244353;
    return 0;
}

詳細信息

Test #1:

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

input:

3
1 2 3

output:

2 6

result:

ok 2 number(s): "2 6"

Test #2:

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

input:

1
1

output:

1 1

result:

ok 2 number(s): "1 1"

Test #3:

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

input:

2
1 1

output:

1 2

result:

ok 2 number(s): "1 2"

Test #4:

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

input:

2
2 2

output:

2 6

result:

ok 2 number(s): "2 6"

Test #5:

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

input:

3
1 1 1

output:

1 3

result:

ok 2 number(s): "1 3"

Test #6:

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

input:

3
2 2 2

output:

2 9

result:

ok 2 number(s): "2 9"

Test #7:

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

input:

3
3 3 3

output:

3 48

result:

ok 2 number(s): "3 48"

Test #8:

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

input:

5
1 1 3 3 4

output:

3 47

result:

ok 2 number(s): "3 47"

Test #9:

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

input:

10
2 4 5 5 5 5 6 8 8 10

output:

5 864

result:

ok 2 number(s): "5 864"

Test #10:

score: -100
Wrong Answer
time: 1ms
memory: 5736kb

input:

30
6 8 9 9 9 10 13 14 15 15 16 17 17 18 20 22 22 23 23 24 24 25 25 25 27 28 28 29 29 30

output:

17 843284081

result:

wrong answer 2nd numbers differ - expected: '986189864', found: '843284081'