QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#682475 | #7875. Queue Sorting | WedonotLikeStudying# | WA | 3ms | 8652kb | C++23 | 1.4kb | 2024-10-27 15:35:55 | 2024-10-27 15:35:55 |
Judging History
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: 0
Wrong Answer
time: 3ms
memory: 8652kb
input:
4 1 1 1 1
output:
0 5 5 3 1 0 2 2 1 0 0 1 1 0 0 0 1 0 0 0 14
result:
wrong answer 1st numbers differ - expected: '14', found: '0'