QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#279669 | #7875. Queue Sorting | Luan_233 | WA | 22ms | 6740kb | C++14 | 1.3kb | 2023-12-08 23:01:34 | 2023-12-08 23:01:35 |
Judging History
answer
#include <cstdio>
#include <cctype>
#include <cstring>
#include <iostream>
#include <algorithm>
#define mod 998244353
const int maxn = 505;
int n,cnt,ai[maxn],sum[maxn];
long long c[maxn][maxn],f[maxn][maxn],ans;
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0),std::cout.tie(0);
std::cin>>n;
for(int i=1,a;i<=n;++i){
std::cin>>a;
if(a) ai[++cnt]=a;
}
n=cnt;
for(int i=1;i<=n;++i) sum[i]=sum[i-1]+ai[i];
c[0][0]=1;
for(int i=1;i<=sum[n];++i){
for(int j=0;j<=i;++j){
if(!j) c[i][j]=c[i-1][j];
else c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;
}
}
f[1][0]=1;
for(int i=1;i<n;++i){
std::memcpy(f[i+1],f[i],sizeof(long long)*maxn);
for(int j=0;j<sum[i];++j){
int res=sum[i]-j;
for(int k=0;k<ai[i+1];++k){
int lim=ai[i+1]-k+res;
for(int l=ai[i+1]-k;l<lim;++l){
(f[i+1][j+l]+=f[i][j]*c[l-1][ai[i+1]-k-1])%=mod;
}
}
}
}
// for(int i=1;i<=n;++i){
// for(int j=0;j<sum[i];++j) std::cout<<f[i][j]<<" ";
// std::cout<<std::endl;
// }
for(int i=0;i<sum[n];++i) ans+=f[n][i];
std::cout<<ans<<std::endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5744kb
input:
4 1 1 1 1
output:
14
result:
ok 1 number(s): "14"
Test #2:
score: -100
Wrong Answer
time: 22ms
memory: 6740kb
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'