QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#585266#6410. Classical DP Problemrotcar07WA 19ms199336kbC++20711b2024-09-23 20:02:322024-09-23 20:02:34

Judging History

你现在查看的是最新测评结果

  • [2024-09-23 20:02:34]
  • 评测
  • 测评结果:WA
  • 用时:19ms
  • 内存:199336kb
  • [2024-09-23 20:02:32]
  • 提交

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'