QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#232905 | #6410. Classical DP Problem | teamariaa | WA | 1ms | 3516kb | C++14 | 1.6kb | 2023-10-31 00:29:37 | 2023-10-31 00:29:37 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int n, k, extra, answer;
vector <int> len, height;
/// PUNE MODUL
int solve(vector <int> &v)
{
vector <vector <int> > dp;
dp.assign(k + 1, vector <int> (extra + 1));
dp[0][extra] = 1;
for(int i = 0; i < k; i ++)
{
for(int 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];
}
int fact(int x)
{
int ans = 1;
for(int 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(int i = 0; i < n; i ++)
cin >> len[i];
len.push_back(0);
reverse(len.begin(), len.end());
k = -1;
for(int i = 1; i <= n; i ++)
k = max(k, min(len[i], i));
cout << k << " ";
for(int i = 1; i <= n; i ++)
for(int 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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3404kb
input:
3 1 2 3
output:
2 6
result:
ok 2 number(s): "2 6"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3460kb
input:
1 1
output:
1 1
result:
ok 2 number(s): "1 1"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3408kb
input:
2 1 1
output:
1 2
result:
ok 2 number(s): "1 2"
Test #4:
score: 0
Accepted
time: 1ms
memory: 3380kb
input:
2 2 2
output:
2 6
result:
ok 2 number(s): "2 6"
Test #5:
score: 0
Accepted
time: 1ms
memory: 3508kb
input:
3 1 1 1
output:
1 3
result:
ok 2 number(s): "1 3"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3420kb
input:
3 2 2 2
output:
2 9
result:
ok 2 number(s): "2 9"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3408kb
input:
3 3 3 3
output:
3 48
result:
ok 2 number(s): "3 48"
Test #8:
score: 0
Accepted
time: 1ms
memory: 3456kb
input:
5 1 1 3 3 4
output:
3 47
result:
ok 2 number(s): "3 47"
Test #9:
score: 0
Accepted
time: 1ms
memory: 3516kb
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: 1ms
memory: 3408kb
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 -204291386
result:
wrong answer 2nd numbers differ - expected: '986189864', found: '-204291386'