QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#232855 | #6410. Classical DP Problem | elisaipate | WA | 1ms | 5744kb | C++14 | 1.1kb | 2023-10-30 23:45:49 | 2023-10-30 23:45:50 |
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++ ) {
if( a[i+1] > 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 << k << " " << 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: 100
Accepted
time: 0ms
memory: 5744kb
input:
3 1 2 3
output:
2 6
result:
ok 2 number(s): "2 6"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5740kb
input:
1 1
output:
1 1
result:
ok 2 number(s): "1 1"
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 5680kb
input:
2 1 1
output:
1 -1
result:
wrong answer 2nd numbers differ - expected: '2', found: '-1'