QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#155642#6410. Classical DP ProblemForever_Young#WA 7ms203208kbC++14828b2023-09-01 22:37:052023-09-01 22:37:06

Judging History

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

  • [2023-09-01 22:37:06]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:203208kb
  • [2023-09-01 22:37:05]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n,a[5050],r,dp[2][5050][5050],res,fac[5050];
const int mo=998244353;
int main(){
	//freopen("D.in","r",stdin);
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for (int i=n;i;i--){
		if (r>=a[i]) break;
		r++;
	}
	dp[0][n][a[n-r]]=1;
	for (int i=n;i>n-r;i--)
		for (int j=0;j<=a[n-r];j++){
			//printf("%d %d %d\n",i,j,dp[0][i][j]);
			dp[0][i-1][j]=(dp[0][i-1][j]+1ll*dp[0][i][j]*(a[i]-j))%mo;
			if (j)
				dp[0][i-1][j-1]=(dp[0][i-1][j-1]+1ll*dp[0][i][j]*j)%mo;
	}
	res=dp[0][n-r][0];
	memset(dp,0,sizeof(dp));
	if (r==a[n-r+1]){
		fac[0]=1;
		for (int i=1;i<=n;i++) fac[i]=1ll*fac[i-1]*i%mo;
		for (int i=1;i<=n-r;i++)
			res=(res+1ll*a[i]*fac[r-1])%mo;
		res=(res+1ll*fac[r]*(r-1)%mo*499122177)%mo;
	}
	printf("%d %d\n",r,res);
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 202996kb

input:

3
1 2 3

output:

2 6

result:

ok 2 number(s): "2 6"

Test #2:

score: 0
Accepted
time: 1ms
memory: 203208kb

input:

1
1

output:

1 1

result:

ok 2 number(s): "1 1"

Test #3:

score: 0
Accepted
time: 7ms
memory: 203100kb

input:

2
1 1

output:

1 2

result:

ok 2 number(s): "1 2"

Test #4:

score: -100
Wrong Answer
time: 4ms
memory: 203004kb

input:

2
2 2

output:

2 5

result:

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