QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#232852#6410. Classical DP ProblemLaurraWA 296ms7948kbC++141.5kb2023-10-30 23:43:532023-10-30 23:43:54

Judging History

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

  • [2023-10-30 23:43:54]
  • 评测
  • 测评结果:WA
  • 用时:296ms
  • 内存:7948kb
  • [2023-10-30 23:43:53]
  • 提交

answer

#include <iostream>
#include <vector>

using namespace std;

#define MOD 998244353
#define dim 5002
#define ll long long
vector<int> v;
int n;
bool ok(int i,int j)
{
    if(i>=1 && v[i]>=j)
        return true;
    return false;
}
ll dp[dim][dim];
ll fact(int k)
{
    ll p=1,i;
    for(i=2;i<=k;i++)
        p*=i;
    return p;
}
void init()
{
    int i,j;
    for(i=0;i<=n;i++)
    {
        for(j=0;j<=n;j++)
            dp[i][j]=0;
    }
}
ll calc(int k)
{
    int x=v[k+1],i,j;
    dp[0][x]=1;
    for(i=0;i<k;i++)
    {
        for(j=0;j<=x;j++)
        {
            if(j)
            {
                dp[i+1][j-1]=(dp[i+1][j-1]+(j*dp[i][j])%MOD)%MOD;
            }
            dp[i+1][j]=(dp[i+1][j]+((v[i+1]-j)*dp[i][j])%MOD)%MOD;
        }
    }
    return dp[k][0]%MOD;
}
void flip()
{
    vector<int> v2(n+1);
    int i,j;
    for(i=1;i<=n;i++)
    {
        j=1;
        while(j<=n && v[j]>=i)
            j++;
        v2[i]=j-1;
    }
    v=v2;
}

int main()
{
    int k,j,i;
    ll tot=0;
    //Citire
    cin>>n;
    v.resize(n+1);
    for(i=1;i<=n;i++)
    {
        cin>>v[n-i+1];
    }
    //Calc nr ture
    k=0;
    j=1;
    i=1;
    while(ok(i,j)==true)
    {
        i++;
        j++;
        k++;
    }
    cout<<k<<" ";
    //Dinamica
    init();
    tot+=calc(k);
    flip();
    init();
    tot%=MOD;
    tot+=calc(k);
    tot-=fact(k);
    while(tot<0)
        tot+=MOD;
    tot%=MOD;
    cout<<tot;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3588kb

input:

3
1 2 3

output:

2 6

result:

ok 2 number(s): "2 6"

Test #2:

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

input:

1
1

output:

1 1

result:

ok 2 number(s): "1 1"

Test #3:

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

input:

2
1 1

output:

1 2

result:

ok 2 number(s): "1 2"

Test #4:

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

input:

2
2 2

output:

2 6

result:

ok 2 number(s): "2 6"

Test #5:

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

input:

3
1 1 1

output:

1 3

result:

ok 2 number(s): "1 3"

Test #6:

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

input:

3
2 2 2

output:

2 9

result:

ok 2 number(s): "2 9"

Test #7:

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

input:

3
3 3 3

output:

3 48

result:

ok 2 number(s): "3 48"

Test #8:

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

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: 3512kb

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: 0
Accepted
time: 0ms
memory: 3724kb

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 986189864

result:

ok 2 number(s): "17 986189864"

Test #11:

score: -100
Wrong Answer
time: 296ms
memory: 7948kb

input:

123
1 1 1 2 2 3 3 6 6 7 7 7 8 8 9 9 10 10 10 11 12 12 12 13 14 14 14 14 16 17 17 17 17 17 18 19 20 20 21 21 22 22 22 23 23 23 25 25 26 27 27 28 28 28 28 29 29 30 31 31 31 32 33 33 33 34 35 35 35 36 37 37 38 39 39 39 39 40 41 41 42 42 42 43 44 48 48 50 52 53 55 56 57 57 57 58 65 68 71 74 75 76 76 82 ...

output:

42 878048363

result:

wrong answer 2nd numbers differ - expected: '287179924', found: '878048363'