QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#282429#6410. Classical DP ProblemGiulian617WA 16ms103608kbC++231.5kb2023-12-12 00:30:072023-12-12 00:30:07

Judging History

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

  • [2023-12-12 00:30:07]
  • 评测
  • 测评结果:WA
  • 用时:16ms
  • 内存:103608kb
  • [2023-12-12 00:30:07]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int NMAX=5005,MOD=998244353;
int n,r,a[NMAX],b[NMAX],aux[NMAX][NMAX],dp[NMAX][NMAX];
///dp[i][j] = number of ways to cover the first i lines and j columns
int find_r()
{
    int ans=1;
    while(ans<=n && a[ans]>=ans)
        ans++;
    return ans-1;
}
void compute_transpose()
{
    for(int i=1; i<=n; i++)
        for(int j=1; j<=a[i]; j++)
            aux[i][j]=1;
    for(int j=1; j<=n; j++)
        for(int i=1; i<=n; i++)
            b[j]+=aux[i][j];
}
int solve(int *a)
{
    int x=a[r+1];///number of lines/columns we must occupy
    memset(dp,0,sizeof(dp));
    dp[0][0]=1;
    for(int i=0; i<r; i++)
        for(int j=0; j<r; j++)
        {
            if(j<x)///we still have to occupy some lines/columns
                dp[i+1][j+1]=(dp[i+1][j+1]+(1LL*(x-j)*dp[i][j])%MOD)%MOD;
            dp[i+1][j]=(dp[i+1][j]+(1LL*(a[i+1]-(x-j))*dp[i][j])%MOD)%MOD;
        }
    return dp[r][x];
}
int find_w(int r)
{
    int fact=1;

    compute_transpose();
    for(int i=1; i<=r; i++)
        fact=(fact*i)%MOD;

    return solve(a)+solve(b)-fact;///ansLines+ansColumns-factorial
    ///if we don't need to compute an answer for the lines
    ///or for the columns, we will get factorial from those functions
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    for(int i=1; i<=n; i++)
        cin>>a[n-i+1];
    r=find_r();
    cout<<r<<' '<<find_w(r);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 102336kb

input:

3
1 2 3

output:

2 6

result:

ok 2 number(s): "2 6"

Test #2:

score: 0
Accepted
time: 16ms
memory: 101640kb

input:

1
1

output:

1 1

result:

ok 2 number(s): "1 1"

Test #3:

score: 0
Accepted
time: 12ms
memory: 102404kb

input:

2
1 1

output:

1 2

result:

ok 2 number(s): "1 2"

Test #4:

score: 0
Accepted
time: 15ms
memory: 101840kb

input:

2
2 2

output:

2 6

result:

ok 2 number(s): "2 6"

Test #5:

score: 0
Accepted
time: 4ms
memory: 102380kb

input:

3
1 1 1

output:

1 3

result:

ok 2 number(s): "1 3"

Test #6:

score: 0
Accepted
time: 8ms
memory: 101772kb

input:

3
2 2 2

output:

2 9

result:

ok 2 number(s): "2 9"

Test #7:

score: 0
Accepted
time: 7ms
memory: 102284kb

input:

3
3 3 3

output:

3 48

result:

ok 2 number(s): "3 48"

Test #8:

score: 0
Accepted
time: 8ms
memory: 102332kb

input:

5
1 1 3 3 4

output:

3 47

result:

ok 2 number(s): "3 47"

Test #9:

score: 0
Accepted
time: 7ms
memory: 103520kb

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: 8ms
memory: 103608kb

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 1841528434

result:

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