QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#684373#6410. Classical DP ProblemhhoppitreeWA 0ms3960kbC++171.3kb2024-10-28 12:59:212024-10-28 12:59:21

Judging History

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

  • [2024-10-28 12:59:21]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3960kb
  • [2024-10-28 12:59:21]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 5005, P = 998244353;

int n, fac[N], inv[N], iFac[N], a[N], b[N];

int calc(int m) {
    int res = 0;
    for (int i = 0; i <= a[m + 1]; ++i) {
        int mul = 1;
        for (int j = 1; j <= m; ++j) mul = 1ll * mul * (a[j] - i) % P;
        res = (res + ((i & 1) ? P - 1ll : 1ll) * fac[a[m + 1]] % P * iFac[i] % P * iFac[a[m + 1] - i] % P * mul) % P;
    }
    return (res % P + P) % P;
}

signed main() {
    scanf("%d", &n);
    for (int i = fac[0] = 1; i <= n; ++i) {
        fac[i] = 1ll * fac[i - 1] * i % P;
        inv[i] = (i == 1 ? 1 : 1ll * (P - P / i) * inv[P % i] % P);
    }
    for (int i = iFac[0] = 1; i <= n; ++i) {
        iFac[i] = 1ll * iFac[i - 1] * inv[i] % P;
    }
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &a[n - i + 1]);
        ++b[n - i + 1];
    }
    for (int i = n; i >= 1; --i) {
        b[i] += b[i + 1];
    }
    int res1 = 0;
    for (int i = 1; ; ++i) {
        if (a[i] < i) {
            res1 = i - 1;
            break;
        }
    }
    int res2 = P - fac[res1];
    res2 = (res2 + calc(res1)) % P;
    for (int i = 1; i <= n; ++i) a[i] = b[i];
    res2 = (res2 + calc(res1)) % P;
    printf("%d %d\n", res1, res2);
    return 0;
}

詳細信息

Test #1:

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

input:

3
1 2 3

output:

2 6

result:

ok 2 number(s): "2 6"

Test #2:

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

input:

1
1

output:

1 1

result:

ok 2 number(s): "1 1"

Test #3:

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

input:

2
1 1

output:

1 1

result:

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