QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#280031#7875. Queue SortingMurphy_RE 0ms0kbC++14935b2023-12-09 13:27:222023-12-09 13:27:23

Judging History

This is the latest submission verdict.

  • [2023-12-09 13:27:23]
  • Judged
  • Verdict: RE
  • Time: 0ms
  • Memory: 0kb
  • [2023-12-09 13:27:22]
  • Submitted

answer

#include<bits/stdc++.h>
#define ll long long
#define il inline
#define mod 998244353
#define N 512
using namespace std;
int c[N][N],f[N][N],a[N],ans;
void init() {
	for(int i=0;i<=N;++i) c[i][0]=c[i][1]=c[i][i]=1;
	for(int i=3;i<=N;++i) for(int j=2;j<i;++j) c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod;
}
int main()
{
	int n;scanf("%d",&n);
	for(int i=1;i<=n;++i) scanf("%d",&a[i]);
	init();
	int t=0;
	f[0][0]=1;
	for(int i=1;i<=n;++i) {
		for(int j=0;j<=t;++j) f[i][j]=f[i-1][j];
		for(int j=0;j<t;++j) {
			for(int k=j;k<t;++k) {
				for(int l=0;l<a[i];++l) {
//					cout<<i<<' '<<j<<' '<<k<<' '<<l<<':'<<i<<' '<<k+l+1<<','<<i-1<<' '<<j<<','<<k-j+l<<' '<<l<<endl;
					f[i][k+l+1]=(f[i-1][j]*c[k-j+l][l]%mod+f[i][k+l+1])%mod;
				}
			}
		}
		t+=a[i];
	}
//	for(int i=1;i<=n;++i) {for(int j=0;j<=t;++j) cout<<f[i][j]<<' ';cout<<endl;}
	for(int j=0;j<t;++j) ans=(ans+f[n][j])%mod;
	cout<<ans;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

4
1 1 1 1

output:


result: