QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#283064 | #6551. Forever Young | UtopianZ | WA | 169ms | 51560kb | C++14 | 2.1kb | 2023-12-13 19:03:37 | 2023-12-13 19:03:39 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
inline int read(){
int sum=0,fh=1;
char c=getchar();
while(c<'0'||c>'9'){
if(c=='-')fh=-1;
c=getchar();
}
while(c>='0'&&c<='9'){
sum=sum*10+c-'0';
c=getchar();
}
return sum*fh;
}
#define maxn 2000009
#define pb push_back
const int mod=998244353;
void add(int &x,int y){
x+=y;if(x>=mod)x-=mod;return ;
}
int fp(int x,int y){
int sum=1;
while(y){
if(y&1)sum=1ll*sum*x%mod;
y>>=1;x=1ll*x*x%mod;
}
return sum;
}
#define fi first
#define se second
#define mp make_pair
int n,m,k,f[maxn],g[maxn];
int fac[maxn],inv[maxn];
vector<int > a,b;
vector<map<vector<int >,int > > mpa,mpb;
void solve(vector<int > x,vector<map<vector<int >,int > > &mpx){
int sum=0;for(auto i:x)sum+=i;
mpx.resize(min(sum+1,k+1));
int siz=x.size();mpx[0][x]=1;
for(int i=0;i<min(k,sum);i++)for(auto j:mpx[i]){
vector<int > o=j.fi;
for(int id=0;id<siz-1;id++)if(o[id]>o[id+1]){
o[id]--;
add(mpx[i+1][o],j.se);
o[id]++;
}
}
return ;
}
void build(){
fac[0]=1;for(int i=1;i<maxn;i++)fac[i]=1ll*fac[i-1]*i%mod;
inv[maxn-1]=fp(fac[maxn-1],mod-2);for(int i=maxn-1;i;i--)inv[i-1]=1ll*inv[i]*i%mod;
return ;
}
int c(int x,int y){
if(x<0||x<y)return 0;
return 1ll*fac[x]*inv[y]%mod*inv[x-y]%mod;
}
int main(){
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
n=read();for(int i=1;i<=n;i++)a.pb(read());
m=read();for(int i=1;i<=n;i++)b.pb(read());
k=read();
build();
int len=max(n,m)+1;
a.resize(len);b.resize(len);
int sa=0,sb=0;
for(auto i:a)sa+=i;
for(auto i:b)sb+=i;
if((sa+sb+k)%2){puts("0");return 0;}
solve(a,mpa);solve(b,mpb);
f[0]=1;for(int i=1;i<=k;i++)f[i]=1ll*f[i-1]*(i*2-1)%mod;
g[0]=1;for(int i=1;i<=k;i++)g[i]=1ll*g[i-1]*(k-i+1)/i%mod;
int ans=0;
for(int i=0;i<=min(sa,sb);i++)if(k>=sa+sb-2*i){
int cnt=0;
for(auto j:mpa[sa-i])if(mpb[sb-i].count(j.fi)){
add(cnt,1ll*j.se*mpb[sb-i][j.fi]%mod);
}
int w=(k-(sa+sb-2*i));
cnt=1ll*cnt*f[w/2]%mod*g[w]%mod*c(sa+sb-2*i,sb-i)%mod;
add(ans,cnt);
}
printf("%d\n",ans);
// fclose(stdin);
// fclose(stdout);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 16ms
memory: 22940kb
input:
3 3 2 1 3 3 2 1 2
output:
7
result:
ok 1 number(s): "7"
Test #2:
score: 0
Accepted
time: 19ms
memory: 19728kb
input:
3 3 2 1 3 3 2 1 1111
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 11ms
memory: 21784kb
input:
0 0 10
output:
945
result:
ok 1 number(s): "945"
Test #4:
score: -100
Wrong Answer
time: 169ms
memory: 51560kb
input:
10 10 9 8 7 6 5 4 4 4 3 10 10 9 8 7 6 5 4 4 4 3 1000000
output:
0
result:
wrong answer 1st numbers differ - expected: '591072522', found: '0'