QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#232903#6410. Classical DP Problemkad_01WA 34ms240008kbC++141.3kb2023-10-31 00:28:162023-10-31 00:28:16

Judging History

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

  • [2023-10-31 00:28:16]
  • 评测
  • 测评结果:WA
  • 用时:34ms
  • 内存:240008kb
  • [2023-10-31 00:28:16]
  • 提交

answer

#include <iostream>

using namespace std;

const int MOD = 998244353;
const int N = 5500;

long long dp[N][N];
int a[N], a1[N], a2[N];

int solve ( int a[], int k ) {
    
    for ( int i = 0; i < N; i++ )
        for ( int j = 0; j < N; j++ )
            dp[i][j] = 0;
    
    dp[0][a[k + 1]] = 1;
    
    for ( int i = 0; i < k; i++ ) {
        for ( int j = 0; j < k + 1; j++ ) {
            if ( j > 0 )
                dp[i + 1][j - 1] += ( dp[i][j] * j ) % MOD;
            dp[i + 1][j] += ( (a[i + 1] - j) * dp[i][j] ) % MOD;
        }
    }
    
    return 0;
}

int main () {
    
    int n;
    long long ans = 0;
    
    cin >> n;
    
    for ( int i = 1; i <= n; i++ )
        cin >> a[n + 1 - i];
    
    int k = 1;
    while ( a[k] >= k )
        k++;
    k--;
    
    cout << k << " ";
    
    if ( a[k] != 0 ) {
        solve ( a, k );
        ans = dp[k][0] % MOD;
    }
    
    for ( int i = 1; i <= n; i++ ) {
        for ( int j = 1; j <= a[i]; j++ )
            a1[j]++;
    }
    
    if ( a1[k] != 0 ) {
        solve ( a1, k );
        ans = ( ans + dp[k][0] ) % MOD;
    }
    
    long long fact = 1;
    for ( int i = 1; i <= k; i++ )
        fact = ( fact * i ) % MOD;
    
    cout << ( ans - fact ) % MOD << "\n";
    
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 32ms
memory: 239948kb

input:

3
1 2 3

output:

2 6

result:

ok 2 number(s): "2 6"

Test #2:

score: 0
Accepted
time: 34ms
memory: 240008kb

input:

1
1

output:

1 1

result:

ok 2 number(s): "1 1"

Test #3:

score: 0
Accepted
time: 23ms
memory: 239876kb

input:

2
1 1

output:

1 2

result:

ok 2 number(s): "1 2"

Test #4:

score: 0
Accepted
time: 19ms
memory: 239948kb

input:

2
2 2

output:

2 6

result:

ok 2 number(s): "2 6"

Test #5:

score: 0
Accepted
time: 29ms
memory: 239944kb

input:

3
1 1 1

output:

1 3

result:

ok 2 number(s): "1 3"

Test #6:

score: 0
Accepted
time: 24ms
memory: 239940kb

input:

3
2 2 2

output:

2 9

result:

ok 2 number(s): "2 9"

Test #7:

score: 0
Accepted
time: 19ms
memory: 239912kb

input:

3
3 3 3

output:

3 48

result:

ok 2 number(s): "3 48"

Test #8:

score: 0
Accepted
time: 33ms
memory: 239872kb

input:

5
1 1 3 3 4

output:

3 47

result:

ok 2 number(s): "3 47"

Test #9:

score: 0
Accepted
time: 23ms
memory: 239952kb

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: 29ms
memory: 239872kb

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 -12054489

result:

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