QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#399541 | #1262. Justice For Everyone | QBF | AC ✓ | 1750ms | 4448kb | C++14 | 2.4kb | 2024-04-26 14:37:07 | 2024-04-26 14:37:07 |
Judging History
answer
#include<bits/stdc++.h>
#define ci const int
#define ll long long
using namespace std;
ci mod=998244353;
ll qk(ll x,int y=mod-2){
ll ans=1;
while(y){
if(y&1)ans=ans*x%mod;
x=x*x%mod,y>>=1;
}
return ans;
}
inline void add(int &x,ci v){
x+=v,x-=x<mod?0:mod;
}
inline void sub(int &x,ci v){
x-=v,x+=x<0?mod:0;
}
ci N=35,M=N*200;
int n,a[N],b[N],t;
int mat[N][N][105];
int fac[M],dfac[M],inv[M],ans[M];
int co[M],cur[M],val[M];
void upd(ci i,ci j,ci d){
for(int x=0;x*2<=d;++x)
mat[i][j][x]=(ll)dfac[x]*dfac[d-2*x]%mod;
}
int A[N][N];
int det(){
int ans=1;
for(int i=1;i<=n;++i){
for(int j=i;j<=n;++j)
if(A[j][i]){
swap(A[i],A[j]);
if(i!=j)ans=mod-ans;
break;
}
if(!A[i][i])return 0;
ci inv=qk(A[i][i]);
ans=(ll)ans*A[i][i]%mod;
for(int j=i;j<=n;++j)A[i][j]=(ll)A[i][j]*inv%mod;
for(int j=i+1;j<=n;++j)
for(int k=n;k>=i;--k)
sub(A[j][k],(ll)A[i][k]*A[j][i]%mod);
}
return ans;
}
int main(){
fac[0]=fac[1]=dfac[0]=dfac[1]=inv[1]=1;
for(int i=2;i<M;++i)
fac[i]=(ll)fac[i-1]*i%mod,
inv[i]=(ll)(mod-mod/i)*inv[mod%i]%mod,
dfac[i]=(ll)dfac[i-1]*inv[i]%mod;
scanf("%d",&n);
for(int i=1;i<=n;++i)scanf("%d",&a[i]);
for(int i=1;i<=n;++i){
scanf("%d",&b[i]),t+=b[i]-a[i];
if(a[i]>b[i])return 0*puts("0");
}
for(int i=1;i<=n;++i)
for(int j=i+1;j<=n;++j)
if((a[i]<a[j])!=(b[i]<b[j]))
return 0*puts("0");
if(t&1)return 0*puts("0");
t>>=1;
for(int i=1;i<=n;++i)
for(int j=1;j<=n;++j){
if(a[i]>b[j])continue;
upd(i,j,b[j]-a[i]);
}
for(int i=0;i<=t;++i){
for(int x=1;x<=n;++x)
for(int y=1;y<=n;++y){
A[x][y]=0;
for(int p=0,tmp=1;p*2<=b[y]-a[x];++p)
add(A[x][y],(ll)tmp*mat[x][y][p]%mod),
tmp=(ll)tmp*i%mod;
}
ans[i]=det();
}
cur[0]=1;
for(int j=0;j<=t;++j)
for(int k=t+1;~k;--k)
cur[k]=((k?cur[k-1]:0)-(ll)cur[k]*j%mod+mod)%mod;
for(int i=0;i<=t;++i){
int tmp=ans[i];
for(int j=0;j<=t;++j)
if(i!=j)
tmp=tmp*qk((i-j+mod)%mod)%mod;
for(int j=0;j<=t+1;++j)val[j]=cur[j];
for(int j=t+1;j;--j){
add(co[j-1],(ll)val[j]*tmp%mod);
add(val[j-1],(ll)val[j]*i%mod);
}
// for(int j=0;j<=t;++j)add(co[j],(ll)cur[j]*tmp%mod);
}
int ans=0;
for(int i=0;i<=t;++i){
ci tmp=(ll)co[i]*((ll)fac[t]*dfac[i]%mod*dfac[t-i]%mod)%mod*fac[i]%mod*fac[2*(t-i)]%mod;
if(i&1)sub(ans,tmp);
else add(ans,tmp);
}
printf("%lld",ans*qk((mod+1)/2,t)%mod);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 4028kb
input:
3 1 2 3 3 4 5
output:
1
result:
ok answer is '1'
Test #2:
score: 0
Accepted
time: 0ms
memory: 4004kb
input:
3 1 2 3 7 8 9
output:
42
result:
ok answer is '42'
Test #3:
score: 0
Accepted
time: 0ms
memory: 4024kb
input:
3 1 4 7 3 6 9
output:
6
result:
ok answer is '6'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3996kb
input:
1 1 3
output:
0
result:
ok answer is '0'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3936kb
input:
1 1 1
output:
1
result:
ok answer is '1'
Test #6:
score: 0
Accepted
time: 0ms
memory: 4064kb
input:
2 1 4 4 7
output:
1
result:
ok answer is '1'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3844kb
input:
10 10 9 8 7 6 1 2 3 4 5 11 12 13 114 115 120 129 128 127 126
output:
0
result:
ok answer is '0'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3924kb
input:
30 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 131
output:
0
result:
ok answer is '0'
Test #9:
score: 0
Accepted
time: 615ms
memory: 4448kb
input:
30 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
output:
936606510
result:
ok answer is '936606510'
Test #10:
score: 0
Accepted
time: 1ms
memory: 3856kb
input:
30 16 21 33 44 51 60 71 81 91 100 110 122 131 144 155 160 162 171 172 174 177 179 187 188 189 191 192 193 194 199 110 111 112 113 114 115 116 117 118 119 120 122 131 144 155 160 162 171 172 174 177 179 187 188 189 191 192 193 194 199
output:
0
result:
ok answer is '0'
Test #11:
score: 0
Accepted
time: 40ms
memory: 4316kb
input:
30 16 21 33 44 51 60 71 81 91 100 110 122 131 144 155 160 162 171 172 174 177 179 187 188 189 191 192 193 194 199 110 111 112 113 114 115 116 117 118 119 120 122 131 144 155 160 162 171 172 174 177 179 187 188 189 191 192 193 194 200
output:
836228983
result:
ok answer is '836228983'
Test #12:
score: 0
Accepted
time: 43ms
memory: 4096kb
input:
10 10 9 8 7 6 5 4 3 2 1 110 109 108 107 106 105 104 103 102 101
output:
422463757
result:
ok answer is '422463757'
Test #13:
score: 0
Accepted
time: 1750ms
memory: 4416kb
input:
30 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
output:
575061951
result:
ok answer is '575061951'