QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#682479#7875. Queue SortingWedonotLikeStudying#WA 31ms8832kbC++231.4kb2024-10-27 15:36:312024-10-27 15:36:32

Judging History

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

  • [2024-10-27 15:36:32]
  • 评测
  • 测评结果:WA
  • 用时:31ms
  • 内存:8832kb
  • [2024-10-27 15:36:31]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i,j,k) for (int i=(j);i<=(k);++i)
#define dep(i,j,k) for (int i=(j);i>=(k);--i)
#define MAXN 500
#define MOD 998244353
using namespace std;
typedef long long LL;

LL dp[MAXN+5][MAXN+5],sum[MAXN+5][MAXN+5];
int a[MAXN+5];
LL nCr[MAXN+5][MAXN+5];

void init() {
    nCr[0][0]=1;
    rep(i,1,MAXN) nCr[i][0]=1;
    rep(i,1,MAXN) {
        rep(j,1,i) {
            nCr[i][j]=(nCr[i-1][j-1]+nCr[i-1][j])%MOD;
        }
    }
    rep(i,0,MAXN) {
        rep(j,1,MAXN) {
            (nCr[i][j]+=nCr[i][j-1])%=MOD;
        }
    }
}

void solve() {
    init();
    int n;
    cin>>n;
    rep(i,1,n) cin>>a[i];
    int tot=0;
    dep(i,n,1) {
        if (!a[i]) {
            rep(j,1,tot+1) dp[i][j]=dp[i+1][j];
            continue;
        }
        tot+=a[i];
        dp[i][tot+1]=1;
        rep(j,2,tot) {
            if (j>a[i]) dp[i][j]=dp[i+1][j-a[i]];
            rep(k,max(1+j-a[i],2),tot-a[i]+1) {
                (dp[i][j]+=dp[i+1][k]*nCr[k+a[i]-j-1][a[i]-1]%MOD)%=MOD;
            }
        }
    }
    // rep(i,1,n) {
    //     rep(j,1,tot+1)
    //         cout<<dp[i][j]<<" ";
    //     cout<<"\n";
    // }
    LL ans=0;
    rep(i,1,tot+1) (ans+=dp[1][i])%=MOD;
    cout<<ans<<"\n";
    return;
}

int main() {
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;
    // cin>>t;
    t=1;
    while (t--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4
1 1 1 1

output:

14

result:

ok 1 number(s): "14"

Test #2:

score: -100
Wrong Answer
time: 31ms
memory: 8832kb

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:

322886583

result:

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