QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#693434#6410. Classical DP ProblemLYY_yyyyWA 3ms101696kbC++141.1kb2024-10-31 16:09:122024-10-31 16:09:23

Judging History

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

  • [2024-10-31 16:09:23]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:101696kb
  • [2024-10-31 16:09:12]
  • 提交

answer

#include<bits/stdc++.h>
#define pb emplace_back
#define ll long long
#define all(b) b.begin(),b.end()
using namespace std;
int n,a[5010],dp[5010][5010],b[5010];
const int mod=998244353;
inline void add(int &x,int y)
{
	x+=y;
	if(x>=mod) x-=mod;
}
int main()
{
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>n;
	int k=0;
	for(int i=1;i<=n;i++) cin>>a[i],k=max(k,min(n-i+1,a[i]));
	cout<<k<<' ';
	int t=a[n-k],ans=0;
	dp[n-k][0]=1;
	for(int i=n-k+1;i<=n;i++)
	{
		for(int j=0;j<=t;j++)
		{
			add(dp[i][j],1ll*(a[i]-t+j)*dp[i-1][j]%mod);
			if(j) add(dp[i][j],1ll*dp[i-1][j-1]*(t-j+1)%mod);
		}
	}
	add(ans,dp[n][t]);
	memset(dp,0,sizeof(dp));
	dp[n-k][0]=1;
	for(int i=1;i<=n;i++) b[n]++,b[n-a[i]]--;
	for(int i=n;i>=1;i--) b[i]+=b[i+1],a[i]=b[i];
	for(int i=n-k+1;i<=n;i++)
	{
		for(int j=0;j<=t;j++)
		{
			add(dp[i][j],1ll*(a[i]-t+j)*dp[i-1][j]%mod);
			if(j) add(dp[i][j],1ll*dp[i-1][j-1]*(t-j+1)%mod);
		}
	}
	add(ans,dp[n][t]);
	int fac=1;
	for(int i=1;i<=k;i++) fac=1ll*fac*i%mod;
	add(ans,mod-fac);
	cout<<ans;
	return 0;
}


详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 101696kb

input:

3
1 2 3

output:

2 6

result:

ok 2 number(s): "2 6"

Test #2:

score: 0
Accepted
time: 0ms
memory: 101624kb

input:

1
1

output:

1 1

result:

ok 2 number(s): "1 1"

Test #3:

score: -100
Wrong Answer
time: 3ms
memory: 101636kb

input:

2
1 1

output:

1 1

result:

wrong answer 2nd numbers differ - expected: '2', found: '1'