QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#232849#6410. Classical DP Problemana_valeriaWA 1ms5596kbC++141.8kb2023-10-30 23:42:352023-10-30 23:42:36

Judging History

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

  • [2023-10-30 23:42:36]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5596kb
  • [2023-10-30 23:42:35]
  • 提交

answer

#include <iostream>
#include <algorithm>
#define MAX 5000
#define MOD 998244353
using namespace std;
///ifstream cin ("c.in");
///ofstream cout ("c.out");
int a[MAX + 10], aux[MAX + 10], dp[MAX + 10][MAX + 10], n;
int findK()
{
    int k = 0;
    for (int i = 1; i <= n && k == 0; i++)
        if (a[i] < i)
            k = i - 1;
    return k;
}
int findX(int k)
{
    return a[k + 1];
}
int kFact(int k)
{
    int p = 1;
    for (int i = 1; i <= k; i++)
        p = 1LL * p * i % MOD;
    return p;
}
int DP(int k)
{
    int x = findX(k);
    for (int i = 0; i <= k; i++)
        for (int j = 0; j <= x; j++)
            dp[i][j] = 0;
    dp[0][x] = 1;
    for (int i = 0; i <= k; i++)
        for (int j = x; j >= 0; j--)
        {
            dp[i + 1][j] = (dp[i + 1][j] + 1LL * (a[i + 1] - j) * dp[i][j] % MOD) % MOD;
            dp[i + 1][j - 1] = (dp[i + 1][j - 1] + 1LL * j * dp[i][j] % MOD) % MOD;
        }
    return dp[k][0];
}
void flip()
{
    int length = 1, dim = 0, last, first;
    for (int i = 2; i <= n; i++)
        if (a[i - 1] == a[i])
            length++;
        else
        {
            last = i - 1;
            first = last - length + 1;
            dim = dim + length;
            for (int j = first; j <= last; j++)
                aux[j] = dim;
            length = 1;
        }
    last = n;
    first = last - length + 1;
    dim = dim + length;
    for (int j = first; j <= last; j++)
        aux[j] = dim;
    for (int i = n; i >= 1; i--)
        a[n - i + 1] = aux[i];
}
int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    reverse(a + 1, a + n + 1);
    int k = findK();
    cout << k << ' ';
    int ans = DP(k);
    flip();
    ans = (ans + DP(k) - kFact(k) + MOD) % MOD;
    cout << ans;
    return 0;
}

詳細信息

Test #1:

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

input:

3
1 2 3

output:

2 6

result:

ok 2 number(s): "2 6"

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3560kb

input:

1
1

output:

0 998244352

result:

wrong answer 1st numbers differ - expected: '1', found: '0'