QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#561805#7875. Queue SortinghuaxiamengjinWA 139ms12648kbC++141.6kb2024-09-13 10:41:542024-09-13 10:41:54

Judging History

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

  • [2024-09-13 10:41:54]
  • 评测
  • 测评结果:WA
  • 用时:139ms
  • 内存:12648kb
  • [2024-09-13 10:41:54]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int NN=998244353;
int p[100100],ni[100100];
int n;
int mi(int x,int y){
	int sum=1;
	for (;y;y>>=1,x=x*x%NN)
	if(y&1)sum=sum*x%NN;
	return sum;
}
int c(int x,int y){
	if(x<0||y<0||x<y)return 0;
	return p[x]*ni[y]%NN*ni[x-y]%NN;
}
int ans=1;
int f[1010][1010][2];
int a[100100];
signed main(){
	cin>>n;
	int N=1e5;
	p[0]=1;
	for (int i=1;i<=N;i++)
	p[i]=p[i-1]*i%NN;
	ni[N]=mi(p[N],NN-2);
	for (int i=N;i;i--)
	ni[i-1]=ni[i]*i%NN;
	for (int i=1;i<=n;i++)
	cin>>a[i];
	int sum=0;
//	for (int i=0;i<a[1];i++)
//	f[1][i][1]=1;
	f[0][0][1]=1;
	
	for (int i=1;i<=n;i++){
		sum+=a[i];
		
		for (int k=0;k<sum;k++)
		f[i][k][0]=f[i-1][k][0],f[i][k][1]=f[i-1][k][1];
		for (int k=0;k<sum;k++){
			if(k+1<sum)f[i][k+1][0]=(f[i][k+1][0]+f[i-1][k][1])%NN;
			for (int kk=k+1;kk<sum;kk++)
			f[i][kk][0]=(f[i][kk][0]+f[i-1][k][0]*c(kk-k-1,0))%NN;
			int kk=sum-(a[i]-1);
			f[i][kk][1]=(f[i][kk][1]+f[i-1][k][0]*c(kk-k-1,0))%NN;
			
		}
		for (int j=2;j<=a[i];j++){
			for (int k=0;k<sum;k++){
				for (int kk=k+j;kk<sum;kk++){
					f[i][kk][0]=(f[i][kk][0]+f[i-1][k][0]*c(kk-k-1,j-1))%NN;
					f[i][kk][0]=(f[i][kk][0]+f[i-1][k][1]*c(kk-k-2,j-2))%NN;
				}
				int kk=sum-(a[i]-j);
				f[i][kk][1]=(f[i][kk][1]+f[i-1][k][0]*c(kk-k-1,j-1))%NN;
				f[i][kk][1]=(f[i][kk][1]+f[i-1][k][1]*c(kk-k-2,j-2))%NN;
			}
		}
//		for (int j=0;j<=sum;j++)
//		cout<<f[i][j][0]<<" "<<f[i][j][1]<<" "<<i<<" "<<j<<"\n";
//		cout<<"*******\n";
		for (int j=0;j<=sum;j++)
		ans=(ans+f[i][j][0])%NN;
	}
	
	cout<<ans<<"\n";

} 

詳細信息

Test #1:

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

input:

4
1 1 1 1

output:

14

result:

ok 1 number(s): "14"

Test #2:

score: -100
Wrong Answer
time: 139ms
memory: 12648kb

input:

300
0 5 2 2 1 0 3 2 2 5 2 1 1 2 1 3 2 3 2 0 0 0 0 1 2 2 3 0 2 2 3 2 0 2 3 0 6 0 0 2 0 1 3 2 1 1 1 3 4 0 1 0 4 1 1 1 1 1 1 2 3 2 1 2 3 2 3 0 5 3 3 2 0 1 1 0 2 1 1 2 0 0 2 1 1 3 2 2 1 2 1 3 0 3 0 1 2 2 0 5 0 2 2 0 0 0 1 2 1 4 2 1 1 0 3 0 2 0 3 1 1 2 0 2 1 1 0 2 0 1 2 2 3 3 1 1 1 1 0 1 3 3 1 0 2 2 4 2 ...

output:

1

result:

wrong answer 1st numbers differ - expected: '507010274', found: '1'