QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#684373 | #6410. Classical DP Problem | hhoppitree | WA | 0ms | 3960kb | C++17 | 1.3kb | 2024-10-28 12:59:21 | 2024-10-28 12:59:21 |
Judging History
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'