QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#585266 | #6410. Classical DP Problem | rotcar07 | WA | 19ms | 199336kb | C++20 | 711b | 2024-09-23 20:02:32 | 2024-09-23 20:02:34 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
constexpr int maxn=5005;
int n,a[maxn],k,b[maxn];
typedef long long ll;
constexpr ll mod=998244353;
ll dp[maxn][maxn],ans;
inline void solve(){
int t=a[k+1];
memset(dp,0,sizeof dp);
dp[0][0]=1;
for(int i=1;i<=k;i++)
for(int j=0;j<=t;j++) dp[i][j]=(dp[i-1][j]*(a[i]-j)+(j?dp[i-1][j-1]*(t-j+1):0))%mod,cout<<i<<' '<<j<<'\n';
ans+=dp[k][t];
}
int main(){
cin>>n;for(int i=1;i<=n;i++) cin>>a[i],k=max(k,min(a[i],n-i+1)),b[i]=a[i];
reverse(a+1,a+n+1);solve();
for(int i=1;i<=n;i++) a[i]=0;
for(int i=1;i<=n;i++) for(int j=1;j<=b[i];j++) a[j]++;
solve();
ll w=1;
for(int i=1;i<=k;i++) w=w*i%mod;
cout<<k<<' '<<(ans+mod-w)%mod<<'\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 19ms
memory: 199336kb
input:
3 1 2 3
output:
1 0 1 1 2 0 2 1 1 0 1 1 2 0 2 1 2 6
result:
wrong answer 1st numbers differ - expected: '2', found: '1'