QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#883825#6410. Classical DP Problemifffer_2137WA 19ms101504kbC++141.8kb2025-02-05 19:12:252025-02-05 19:12:27

Judging History

This is the latest submission verdict.

  • [2025-02-05 19:12:27]
  • Judged
  • Verdict: WA
  • Time: 19ms
  • Memory: 101504kb
  • [2025-02-05 19:12:25]
  • Submitted

answer

//From: ifffer_2137
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define inf 0x3f3f3f3f
#define eb emplace_back
#define pii pair<int,int>
#define mkpr make_pair
#define fir first
#define sec second
#define arr(x) array<int,x>
inline int read(){
	char ch=getchar();int x=0,w=1;
	while(ch<'0'||ch>'9'){if(ch=='-')w=0;ch=getchar();}
	while(ch>='0'&&ch<='9')x=x*10+(ch^48),ch=getchar();
	return w?x:-x;
}
inline bool getmn(auto &x,auto y){if(y<x)return x=y,1;return 0;}
inline bool getmx(auto &x,auto y){if(y>x)return x=y,1;return 0;}
mt19937 rnd(time(NULL));
constexpr int maxn=5e3+5;
constexpr int mod=998244353;
inline int Redu(int x){return x>=mod?x-mod:x;}
inline void Add(int &x,int y){x=Redu(x+y);}
inline int Pow(int a,int x){int s=1;for(;x;x>>=1,a=1ll*a*a%mod)if(x&1)s=1ll*s*a%mod;return s;}
int n,m,k;
int a[maxn],b[maxn];
int dp[maxn][maxn];
signed main(){
	#ifdef LOCAL
	assert(freopen("data.in","r",stdin));
	assert(freopen("test.out","w",stdout));
	#endif
	cin.tie(0),cout.tie(0);
	n=read();b[1]=n;
	for(int i=1;i<=n;i++) a[i]=read(),b[a[i]+1]--;
	for(int i=2;i<=n;i++) b[i]+=b[i-1];
	for(m=1;m<n&&a[n-m]>=m+1;m++);
	k=a[n-m];
	memset(dp,0,sizeof(dp));
	dp[n-m][0]=1;
	for(int i=n-m+1;i<=n;i++){
		dp[i][0]=1ll*dp[i-1][0]*a[i]%mod;
		for(int j=1;j<=k;j++) dp[i][j]=(1ll*dp[i-1][j]*(a[i]-(k-j+1))+1ll*dp[i-1][j-1]*(k-j+1))%mod;
	}
	int res1=dp[n][k];
	k=b[m+1];
	memset(dp,0,sizeof(dp));
	dp[m+1][0]=1;
	for(int i=m;i>=1;i--){
		dp[i][0]=1ll*dp[i+1][0]*b[i]%mod;
		for(int j=1;j<=k;j++) dp[i][j]=(1ll*dp[i+1][j]*(b[i]-(k-j+1))+1ll*dp[i+1][j-1]*(k-j+1))%mod;
	}
	int res2=dp[1][k];
	int fac=1;for(int i=1;i<=m;i++) fac=1ll*fac*i%mod;
	cout<<m<<' '<<(res1+res2-fac+mod)%mod<<'\n';
	//cerr<<1.0*clock()/CLOCKS_PER_SEC<<'\n';
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 19ms
memory: 101360kb

input:

3
1 2 3

output:

2 6

result:

ok 2 number(s): "2 6"

Test #2:

score: -100
Wrong Answer
time: 13ms
memory: 101504kb

input:

1
1

output:

1 0

result:

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