QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#232872 | #6410. Classical DP Problem | bianca | WA | 1ms | 7732kb | C++14 | 1.4kb | 2023-10-31 00:03:54 | 2023-10-31 00:03:54 |
Judging History
answer
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
#define MaxN 5000
#define MOD 998244353
int a[MaxN], b[MaxN];
long long int dp[MaxN][MaxN];
long long int dinamic(int a[], int k, int x)
{
dp[0][x]=1;
int i, j;
for(i=0; i<k; i++)
{
for(j=x; j>=0; j--)
{
dp[i+1][j]+=(a[i+1]-j)*dp[i][j];
dp[i+1][j]%=MOD;
if(j>0)
{
dp[i+1][j-1]+=j*dp[i][j];
dp[i+1][j-1]%=MOD;
}
}
}
return dp[k][0];
}
int fact(int k)
{
int prod=1;
while(k>0)
{
prod=prod*k;
prod%=MOD;
k--;
}
return prod;
}
int main()
{
int n, i, j, k, x=0, res;
cin>>n;
for(i=1; i<=n; i++)
{
cin>>a[i];
}
reverse(a+1, a+n+1);
k=0;
while(k<=n && a[k]>=k)
{
k++;
}
k--;
cout<<k<<" ";
x=a[k+1];
res+=dinamic(a, k, x);
for(i=n; i>0; i--)
{
j=1;
while(a[j]>=i)
{
j++;
}
b[i]=j-1;
}
x=b[k+1];
for(i=0; i<=n; i++)
{
for(j=0; j<=n; j++)
{
dp[i][j]=0;
}
}
res+=dinamic(b, k, x);
res%=MOD;
res-=fact(k);
cout<<res;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3620kb
input:
3 1 2 3
output:
2 6
result:
ok 2 number(s): "2 6"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3544kb
input:
1 1
output:
1 1
result:
ok 2 number(s): "1 1"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3708kb
input:
2 1 1
output:
1 2
result:
ok 2 number(s): "1 2"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
2 2 2
output:
2 6
result:
ok 2 number(s): "2 6"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3700kb
input:
3 1 1 1
output:
1 3
result:
ok 2 number(s): "1 3"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
3 2 2 2
output:
2 9
result:
ok 2 number(s): "2 9"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
3 3 3 3
output:
3 48
result:
ok 2 number(s): "3 48"
Test #8:
score: 0
Accepted
time: 0ms
memory: 3720kb
input:
5 1 1 3 3 4
output:
3 47
result:
ok 2 number(s): "3 47"
Test #9:
score: 0
Accepted
time: 0ms
memory: 3644kb
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: 7732kb
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 583186136
result:
wrong answer 2nd numbers differ - expected: '986189864', found: '583186136'