QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#683657#6410. Classical DP ProblemSimonLJKWA 24ms199644kbC++17843b2024-10-27 22:32:442024-10-27 22:32:44

Judging History

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

  • [2024-10-27 22:32:44]
  • 评测
  • 测评结果:WA
  • 用时:24ms
  • 内存:199644kb
  • [2024-10-27 22:32:44]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=998244353;
const int N=5009;
int n,m,len,x[N],y[N];
ll f[N][N],jc[N],ans;
void init(){
	jc[0]=1;
	for(int i=1;i<=n;i++) jc[i]=jc[i-1]*i%mod;
	return;
}
void solve(){
	int len=0;
	while(x[len+1]>m) len++;
	memset(f,0,sizeof(f));
	f[0][0]=1;
	for(int i=1;i<=m;i++)
		for(int j=0;j<=min(i,len);j++)
			f[i][j]=((j==0?0:f[i-1][j-1]*(len-(j-1)))+f[i-1][j]*(j+x[i]-len))%mod;
	ans+=f[m][len];
	return;
}
int main(){
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n; init();
	for(int i=n;i>=1;i--){
		cin>>x[i];
		y[x[i]+1]--;
	}
	y[1]=n;
	for(int i=1;i<=n;i++) y[i]+=y[i-1];
	m=1;
	while(x[m+1]>m) m++;
	solve();
	for(int i=1;i<=n;i++) swap(x[i],y[i]);
	solve();
	ans=(ans-jc[m]+mod)%mod;
	cout<<m<<" "<<ans;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 24ms
memory: 199644kb

input:

3
1 2 3

output:

2 6

result:

ok 2 number(s): "2 6"

Test #2:

score: 0
Accepted
time: 19ms
memory: 199644kb

input:

1
1

output:

1 1

result:

ok 2 number(s): "1 1"

Test #3:

score: -100
Wrong Answer
time: 24ms
memory: 199596kb

input:

2
1 1

output:

1 1

result:

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