QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#232825#6410. Classical DP ProblemLaurraWA 1ms3828kbC++141.4kb2023-10-30 23:15:142023-10-30 23:15:14

Judging History

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

  • [2023-10-30 23:15:14]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3828kb
  • [2023-10-30 23:15:14]
  • 提交

answer

#include <iostream>
#include <vector>

using namespace std;

#define MOD 998244353
#define dim 5002
#define ll int
vector<int> v;
int n;
bool ok(int i,int j)
{
    if(i>=1 && v[i]>=j)
        return true;
return false;
}
int 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<n;i++)
    {
        for(j=0;j<=x;j++)
        {
            if(j)
            {
                dp[i+1][j-1]=(dp[i+1][j-1]+j*dp[i][j])%MOD;
            }
            dp[i+1][j]=(dp[i+1][j]+(v[i+1]-j)*dp[i][j])%MOD;
        }
    }
    return dp[k][0];
}
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<<" ";
    tot=-fact(k);
    //Dinamica
    init();
    tot+=calc(k);
    flip();
    init();
    tot+=calc(k);
    cout<<tot;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
1 2 3

output:

2 6

result:

ok 2 number(s): "2 6"

Test #2:

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

input:

1
1

output:

1 1

result:

ok 2 number(s): "1 1"

Test #3:

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

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

input:

3
1 1 1

output:

1 3

result:

ok 2 number(s): "1 3"

Test #6:

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

input:

3
2 2 2

output:

2 9

result:

ok 2 number(s): "2 9"

Test #7:

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

input:

3
3 3 3

output:

3 48

result:

ok 2 number(s): "3 48"

Test #8:

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

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

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: 0ms
memory: 3716kb

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 1070420718

result:

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