QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#153702#6410. Classical DP ProblemqzezWA 2ms5716kbC++141.5kb2023-08-30 19:14:472023-08-30 19:14:47

Judging History

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

  • [2023-08-30 19:14:47]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:5716kb
  • [2023-08-30 19:14:47]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<typename T>
ostream& operator << (ostream &out,const vector<T>&x){
	if(x.empty())return out<<"[]";
	out<<'['<<x[0];
	for(int len=x.size(),i=1;i<len;i++)out<<','<<x[i];
	return out<<']';
}
template<typename T>
vector<T> ary(const T *a,int l,int r){
	return vector<T>{a+l,a+1+r};
}
template<typename T>
void debug(T x){
	cerr<<x<<'\n';
}
template<typename T,typename ...S>
void debug(T x,S ...y){
	cerr<<x<<' ',debug(y...);
}
const int N=5e3+10,mod=998244353;
int n,a[N][N],dis[N][N],cnt[N][N],f[N][N];
int main(){
	cin>>n;
	for(int i=n,x;i>=1;i--){
		cin>>x;
		for(int j=1;j<=x;j++)a[i][j]=1;
	}
	for(int i=n;i>=1;i--){
		for(int j=n;j>=1;j--){
			if(a[i][j]){
				dis[i][j]=dis[i+1][j+1]+1;
				cnt[i][j]=cnt[i+1][j]+cnt[i][j+1]-cnt[i+1][j+1]+1;
			}
		}
	}
	cout<<dis[1][1]<<' ';
	f[1][1]=1;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(dis[i+1][j+1]+1==dis[i][j]){
				f[i+1][j+1]=(f[i+1][j+1]+1ll*f[i][j]*dis[i][j]*dis[i][j])%mod;
			}
			if(dis[i+1][j]+1==dis[i][j]){
				f[i+1][j]=(f[i+1][j]+1ll*f[i][j]*cnt[i+dis[i][j]][j])%mod;
			}
			if(dis[i][j+1]+1==dis[i][j]){
				f[i][j+1]=(f[i][j+1]+1ll*f[i][j]*cnt[i][j+dis[i][j]])%mod;
			}
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(!a[i][j]){
				(ans+=f[i][j])%=mod;
			}
		}
	}
	cout<<ans<<endl;
	// for(int i=1;i<=n;i++)debug(ary(f[i],1,n));
	// for(int i=1;i<=n;i++)debug(ary(cnt[i],1,n));
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 5608kb

input:

3
1 2 3

output:

2 6

result:

ok 2 number(s): "2 6"

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 5716kb

input:

1
1

output:

1 0

result:

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