QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#275199 | #7875. Queue Sorting | ucup-team902# | WA | 31ms | 6140kb | C++20 | 2.7kb | 2023-12-04 14:58:52 | 2023-12-04 14:58:53 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define cs const
#define re register
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define y1 shinkle
#define fi first
#define se second
#define bg begin
namespace IO{
#define gc getchar
inline int read(){
char ch=gc();
int res=0;bool f=1;
while(!isdigit(ch))f^=ch=='-',ch=gc();
while(isdigit(ch))res=(res*10)+(ch^48),ch=gc();
return f?res:-res;
}
inline ll readll(){
char ch=gc();
ll res=0;bool f=1;
while(!isdigit(ch))f^=ch=='-',ch=gc();
while(isdigit(ch))res=(res*10)+(ch^48),ch=gc();
return f?res:-res;
}
inline char readchar(){
char ch=gc();
while(isspace(ch))ch=gc();
return ch;
}
inline int readstring(char *s){
int top=0;char ch=gc();
while(isspace(ch))ch=gc();
while(!isspace(ch)&&ch!=EOF)s[++top]=ch,ch=gc();
s[top+1]='\0';return top;
}
}
using IO::read;
using IO::readll;
using IO::readchar;
using IO::readstring;
template<typename tp>inline void chemx(tp &a,tp b){(a<b)?(a=b):0;}
template<typename tp>inline void chemn(tp &a,tp b){(a>b)?(a=b):0;}
cs int mod=998244353;
inline int add(int a,int b){return (a+b)>=mod?(a+b-mod):(a+b);}
inline int dec(int a,int b){return (a<b)?(a-b+mod):(a-b);}
inline int mul(int a,int b){static ll r;r=(ll)a*b;return (r>=mod)?(r%mod):r;}
inline void Add(int &a,int b){a=(a+b)>=mod?(a+b-mod):(a+b);}
inline void Dec(int &a,int b){a=(a<b)?(a-b+mod):(a-b);}
inline void Mul(int &a,int b){static ll r;r=(ll)a*b;a=(r>=mod)?(r%mod):r;}
inline int ksm(int a,int b,int res=1){for(;b;b>>=1,Mul(a,a))(b&1)&&(Mul(res,a),1);return res;}
inline int Inv(int x){return ksm(x,mod-2);}
inline int fix(ll x){x%=mod;return (x<0)?x+mod:x;}
cs int N=505;
int f[N][N];
int a[N],c[N][N],n;
int s[N][N];
int calc(int x,int t,int y,int l){
int l1=max(0,y-x),r1=min(l,y-t);
int xx=s[l][r1];
if(l1>r1)return 0;
if(l1)xx=dec(xx,s[l][l1-1]);
return xx;
}
void solve(){
for(int i=0;i<N;i++){
c[i][i]=c[i][0]=1;
for(int j=1;j<i;j++)c[i][j]=add(c[i-1][j],c[i-1][j-1]);
s[i][0]=c[i][0];
for(int j=1;j<i;j++)s[i][j]=add(s[i][j-1],c[i][j]);
}
n=read();
for(int i=1;i<=n;i++)a[i]=read();
int s=0;
for(int i=1;i<=n;i++){
if(a[i]){
if(s==0){
f[i][0]=1;
s+=a[i];
}
else{
for(int j=0;j<=s;j++){
Add(f[i][j],f[i-1][j]);
for(int k=j+1;k<=s+a[i];k++){
Add(f[i][k],mul(f[i-1][j],calc(min(a[i]-1,s+a[i]-k-1),max(0,a[i]-1-(k-j-1)),a[i]-1,k-j-1)));
}
}
s+=a[i];
}
}
else{
memcpy(f[i],f[i-1],sizeof(f[i]));;
}
}
int res=0;
for(int i=0;i<=s;i++)Add(res,f[n][i]);
cout<<res<<'\n';
}
int main(){
#ifdef Stargazer
freopen("1.in","r",stdin);
#endif
int T=1;
while(T--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5436kb
input:
4 1 1 1 1
output:
14
result:
ok 1 number(s): "14"
Test #2:
score: -100
Wrong Answer
time: 31ms
memory: 6140kb
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:
765797540
result:
wrong answer 1st numbers differ - expected: '507010274', found: '765797540'