QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#232841 | #6410. Classical DP Problem | elisaipate | WA | 1ms | 5684kb | C++14 | 1.0kb | 2023-10-30 23:35:03 | 2023-10-30 23:35:04 |
Judging History
answer
#include <iostream>
using namespace std;
#define nmax 5001
#define mod 998244353
int lin[nmax], col[nmax];
long long dp[2][nmax][nmax], n, k;
void fctdp( int ind, int a[] ) {
int i, j;
for( i = 0; i < k; i++ ) {
for( j = 0; j < k; j++ ) {
dp[ind][i+1][j] += (a[i+1] - j) * dp[ind][i][j] % mod;
if( j >= 1 )
dp[ind][i+1][j-1] += j*dp[ind][i][j] % mod;
}
}
}
int main()
{
int i, nr;
long long fact;
cin >> n;
for( i = n; i >= 1; i-- )
cin >> lin[i];
nr = n;
for( i = 1; i <= n; i++) {
while( lin[nr] < i )
nr--;
col[i] = nr;
}
k = 1;
while( lin[k] >= k )
k++;
k--;
dp[0][0][lin[k+1]] = 1;
dp[1][0][col[k+1]] = 1;
fctdp( 0, lin );
fctdp( 1, col );
fact = 1;
for( i = 2; i <= k; i++ )
fact = fact * i % mod;
cout << dp[0][k][0] + dp[1][k][0] - fact;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5684kb
input:
3 1 2 3
output:
6
result:
wrong answer 1st numbers differ - expected: '2', found: '6'