QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#561808 | #7875. Queue Sorting | huaxiamengjin | WA | 140ms | 10224kb | C++14 | 1.6kb | 2024-09-13 10:44:28 | 2024-09-13 10:44:28 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int NN=998244353;
int p[100100],ni[100100];
int n;
int mi(int x,int y){
int sum=1;
for (;y;y>>=1,x=x*x%NN)
if(y&1)sum=sum*x%NN;
return sum;
}
int c(int x,int y){
if(x<0||y<0||x<y)return 0;
return p[x]*ni[y]%NN*ni[x-y]%NN;
}
int ans=1;
int f[1010][1010][2];
int a[100100];
signed main(){
cin>>n;
int N=1e5;
p[0]=1;
for (int i=1;i<=N;i++)
p[i]=p[i-1]*i%NN;
ni[N]=mi(p[N],NN-2);
for (int i=N;i;i--)
ni[i-1]=ni[i]*i%NN;
for (int i=1;i<=n;i++)
cin>>a[i];
int sum=0;
// for (int i=0;i<a[1];i++)
// f[1][i][1]=1;
f[0][0][1]=1;
for (int i=1;i<=n;i++){
sum+=a[i];
for (int k=0;k<=sum;k++)
f[i][k][0]=f[i-1][k][0],f[i][k][1]=f[i-1][k][1];
if(a[i]>=1)
for (int k=0;k<sum;k++){
if(k+1<sum)f[i][k+1][0]=(f[i][k+1][0]+f[i-1][k][1])%NN;
for (int kk=k+1;kk<sum;kk++)
f[i][kk][0]=(f[i][kk][0]+f[i-1][k][0]*c(kk-k-1,0))%NN;
int kk=sum-(a[i]-1);
f[i][kk][1]=(f[i][kk][1]+f[i-1][k][0]*c(kk-k-1,0))%NN;
}
for (int j=2;j<=a[i];j++){
for (int k=0;k<sum;k++){
for (int kk=k+j;kk<sum;kk++){
f[i][kk][0]=(f[i][kk][0]+f[i-1][k][0]*c(kk-k-1,j-1))%NN;
f[i][kk][0]=(f[i][kk][0]+f[i-1][k][1]*c(kk-k-2,j-2))%NN;
}
int kk=sum-(a[i]-j);
f[i][kk][1]=(f[i][kk][1]+f[i-1][k][0]*c(kk-k-1,j-1))%NN;
f[i][kk][1]=(f[i][kk][1]+f[i-1][k][1]*c(kk-k-2,j-2))%NN;
}
}
// for (int j=0;j<=sum;j++)
// cout<<f[i][j][0]<<" "<<f[i][j][1]<<" "<<i<<" "<<j<<"\n";
// cout<<"*******\n";
for (int j=0;j<=sum;j++)
ans=(ans+f[i][j][0])%NN;
}
cout<<ans<<"\n";
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 6700kb
input:
4 1 1 1 1
output:
14
result:
ok 1 number(s): "14"
Test #2:
score: -100
Wrong Answer
time: 140ms
memory: 10224kb
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:
807450775
result:
wrong answer 1st numbers differ - expected: '507010274', found: '807450775'