QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#271783 | #7875. Queue Sorting | ucup-team2279# | RE | 0ms | 5608kb | C++20 | 1.1kb | 2023-12-02 14:33:31 | 2023-12-02 14:33:31 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mk make_pair
#define lowbit(x) (x&(-x))
#define pb emplace_back
#define pr pair<int,int>
#define let const auto
#define all(A) A.begin(),A.end()
const int N=505,mod=998244353;
int read(){
int x=0,f=1; char c=getchar();
while(('0'>c||c>'9')&&c!='-') c=getchar();
if(c=='-') f=0,c=getchar();
while('0'<=c&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return f?x:-x;
}
int C[N][N],n,a[N],pre[N][N];
int f[N][N];
int main(){
n=read();
for(int i=1; i<=n; i++) a[i]=read();
for(int i=0; i<=n*2; i++){
C[i][0]=pre[i][0]=1;
for(int j=1; j<=i; j++) C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod,pre[i][j]=(pre[i][j-1]+C[i][j])%mod;
}
int sum=a[1];
f[1][0]=1;
for(int i=2; i<=n; sum+=a[i],i++){
for(int j=0; j<sum; j++)
for(int k=j; k<sum+a[i]; k++){
if(k==j) f[i][k]=(f[i][k]+f[i-1][j])%mod;
else if(a[i])
f[i][k]=(f[i][k]+1ll*f[i-1][j]*pre[k-j-1][min({k-j-1,sum-j-1,a[i]-1})])%mod;
}
}
printf("%lld\n",accumulate(f[n],f[n]+sum+1,0ll)%mod);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5608kb
input:
4 1 1 1 1
output:
14
result:
ok 1 number(s): "14"
Test #2:
score: -100
Runtime Error
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 ...