QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#670104#7875. Queue SortingwzxtslWA 145ms5512kbC++231.9kb2024-10-23 20:30:102024-10-23 20:30:10

Judging History

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

  • [2024-10-23 20:30:10]
  • 评测
  • 测评结果:WA
  • 用时:145ms
  • 内存:5512kb
  • [2024-10-23 20:30:10]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define For(i,j,k) for (int i=(j);i<=(k);i++)
#define rof(i,j,k) for (int i=(j);i>=(k);i--)
#define ull unsigned long long
#define lowbit(x) ((x)&(-(x)))
#define PII pair<int,int>
#define int long long
#define endl "\n"
#define ls rt<<1
#define rs rt<<1|1
typedef long long ll;
const int mod = 998244353;
const double eps = 1e-9;
const int N=1007;
int n,m;
int a[N];
long long f[N], g[N],inv[N];
int sum[N];
int dp[N][N];
long long p = 998244353;
long long qpow(long long a, long long n)
{
    long long result = 1;
    while (n > 0)
    {
        if (n & 1)
        {
            result = result * a % p;
        }
        a = a * a % p;
        n >>= 1;
    }
    return result % p;
}
void init()
{
	int n=1000;
    f[0] = g[0] = 1;
    inv[1]=inv[0]=1;
    //for(int i=2;i<=n;i++){
        //inv[i]=inv[p%i]*(p-p/i)%p;//线性筛求逆元
    //}
    for (int i = 1; i <= n; i++)
    {
        f[i] = f[i - 1] * i % p;
    }
    g[n-1]=qpow(f[n-1],p-2);
    for(int i=n-2;i>=0;i--){
        g[i]=g[i+1]*(i+1)%p;
    }
}
long long C(long long n, long long m)
{
    return (f[n] * g[m]) % p * g[n - m] % p;
}
void solve(){
	cin>>n;
	init();
	for(int i=1;i<=n;i++){
        cin>>a[i];
		sum[i]=sum[i-1]+a[i];
    }
	dp[0][0]=1;
    for(int i=0;i<n;i++){
		for(int j=0;j<=sum[i];j++){
			if(dp[i][j]){
				dp[i+1][j]=(dp[i+1][j]+dp[i][j])%mod;
				for(int k=j+1;k<sum[i+1];k++){
					int lb=max(0ll,a[i+1]-(k-j));
					int ub=min(a[i+1]-1,sum[i+1]-k-1);
					for(int x=lb;x<=ub;x++){
						dp[i+1][k]=(dp[i+1][k]+dp[i][j]*C(k-j-1,a[i+1]-x-1)%mod)%mod;
					}
				}
			}
		}
	}
	int ans=0;
	for(int i=0;i<sum[n];i++){
		(ans+=dp[n][i])%mod;
	}
	cout<<ans<<endl;
}
signed main(){
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3652kb

input:

4
1 1 1 1

output:

14

result:

ok 1 number(s): "14"

Test #2:

score: -100
Wrong Answer
time: 145ms
memory: 5512kb

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:

246075121112

result:

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