QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#232910 | #6410. Classical DP Problem | teamariaa | WA | 0ms | 3844kb | C++14 | 1.7kb | 2023-10-31 00:32:03 | 2023-10-31 00:32:04 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
long long n, k, extra, answer;
vector <long long> len, height;
/// PUNE MODUL
long long solve(vector <long long> &v)
{
vector <vector <long long> > dp;
dp.assign(k + 1, vector <long long> (extra + 1));
dp[0][extra] = 1;
for(long long i = 0; i < k; i ++)
{
for(long long j = extra; j >= 0; j --)
{
dp[i + 1][j] += 1ll *((v[i + 1] - j) * dp[i][j]) % mod;
dp[i + 1][j] %= mod;
if(j > 0)
{
dp[i + 1][j - 1] += (j * dp[i][j]) % mod;
dp[i + 1][j - 1] %= mod;
}
}
}
return dp[k][0];
}
long long fact(long long x)
{
long long ans = 1;
for(long long i = 2; i <= x; i ++)
ans = (1ll * ans * i) % mod;
return ans;
}
int main()
{
ios_base :: sync_with_stdio(0);
cin.tie(0);
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
cin >> n;
len.resize(n); ///mortii masii
height.resize(n + 1);
for(long long i = 0; i < n; i ++)
cin >> len[i];
len.push_back(0);
reverse(len.begin(), len.end());
k = -1;
for(long long i = 1; i <= n; i ++)
k = max(k, min(len[i], i));
cout << k << " ";
for(long long i = 1; i <= n; i ++)
for(long long j = 1; j <= len[i]; j ++)
height[j] ++;
extra = len[k + 1];
answer = solve(len);
extra = height[k + 1];
answer += solve(height);
answer %= mod;
answer -= fact(k);
answer %= mod;
cout << answer;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3584kb
input:
3 1 2 3
output:
2 6
result:
ok 2 number(s): "2 6"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
1 1
output:
1 1
result:
ok 2 number(s): "1 1"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
2 1 1
output:
1 2
result:
ok 2 number(s): "1 2"
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3844kb
input:
2 2 2
output:
2 2
result:
wrong answer 2nd numbers differ - expected: '6', found: '2'