QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#389857 | #1262. Justice For Everyone | Ustinian26 | AC ✓ | 1008ms | 3808kb | C++14 | 2.8kb | 2024-04-14 20:30:24 | 2024-04-14 20:30:24 |
Judging History
answer
#include<bits/stdc++.h>
#define L(i,s,t) for(int i=(s);i<=(t);++i)
#define R(i,s,t) for(int i=(s);i>=(t);--i)
#define T(i,s,t) for(int i=(s);i< (t);++i)
#define iV inline void
#define iI inline int
#define iB inline bool
#define ll long long
#define il inline ll
#define I(x) (1<<(x))
#define lb(x) (x&(-x))
#define eb emplace_back
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define pt putchar
using namespace std;
const int N=33,M=6003,P=998244353;
iI add(int x) {return x>=P?x-P:x;}
iI dcl(int x) {return x< 0?x+P:x;}
iV Add(int &x,int y) {(x+=y)>=P&&(x-=P);}
iV Dcl(int &x,int y) {(x-=y)< 0&&(x+=P);}
iV Mul(int &x,int y) {x=1ll*x*y%P;}
iI qpw(int x,int p=P-2) {
int s=1;
for(;p;p>>=1,Mul(x,x)) if(p&1) Mul(s,x);
return s;
}
int n,U,a[N],b[N],det[N][N],fac[M],inv[M];
int f[M],g[M];
iI clc(int v) {
L(i,1,n) L(j,1,n) {
int c=b[j]-a[i],s=0,t=1;
L(y,0,c>>1) {
int k=1ll*inv[y]*inv[c-2*y]%P*t%P;
y&1?Dcl(s,k):Add(s,k);Mul(t,v);
}det[i][j]=s;
}
bool o=0;
L(i,1,n) {
int p=i;
L(j,i+1,n) if(det[j][i]>det[p][i]) p=j;
if(p^i) o^=1,swap(det[i],det[p]);
if(!det[i][i]) return 0;
int v=qpw(det[i][i]);
L(j,i+1,n) if(det[j][i]) {
int d=1ll*det[j][i]*v%P;
L(k,i,n) Dcl(det[j][k],1ll*d*det[i][k]%P);
}
}
int ans=1;
L(i,1,n) Mul(ans,det[i][i]);
return o?add(P-ans):ans;
}
int main() {
// freopen("test.out","w",stdout);
cin>>n;
L(i,1,n) cin>>a[i],U-=a[i];
L(i,1,n) cin>>b[i],U+=b[i];
L(i,1,n) if(a[i]>b[i]) return cout<<"0\n",0;
static int I[N];
L(i,1,n) I[i]=i;
sort(I+1,I+n+1,[](int x,int y){return a[x]<a[y];});
T(i,1,n) if(b[I[i]]>=b[I[i+1]]) return cout<<"0\n",0;
if(U&1) return cout<<"0\n",0;
fac[0]=1;
L(i,1,U) fac[i]=1ll*fac[i-1]*i%P;
inv[U]=qpw(fac[U]);
R(i,U,1) inv[i-1]=1ll*inv[i]*i%P;
U>>=1,f[0]=1;
auto mul=[&](int *d,int v){
R(i,U,1) d[i]=dcl(d[i-1]-1ll*d[i]*v%P);
Mul(d[0],P-v);
};
L(i,0,U) {
int v=1ll*inv[i]*inv[U-i]%P*clc(i)%P;
if((U-i)&1) v=add(P-v);
L(j,0,U) Add(g[j],1ll*f[j]*v%P);
if(i<U) mul(g,i+1);
mul(f,i);
}
// L(i,0,U) cout<<g[i]<<" \n"[i==U];
// static int h[M];
// L(i,0,U) {
// int v=1ll*inv[i]*inv[U-i]%P*clc(i)%P;
// if((U-i)&1) v=add(P-v);
// memset(f,0,sizeof(f)),f[0]=1;
// L(j,0,U) if(i^j) mul(f,j);
// L(j,0,U) Add(h[j],1ll*f[j]*v%P);
// }
// L(i,0,U) cout<<h[i]<<" \n"[i==U];
int ans=0;
L(i,0,U) Add(ans,1ll*inv[U-i]*fac[2*(U-i)]%P*g[i]%P);
cout<<1ll*ans*fac[U]%P*qpw(qpw(2,U))%P<<"\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3680kb
input:
3 1 2 3 3 4 5
output:
1
result:
ok answer is '1'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3676kb
input:
3 1 2 3 7 8 9
output:
42
result:
ok answer is '42'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3680kb
input:
3 1 4 7 3 6 9
output:
6
result:
ok answer is '6'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3680kb
input:
1 1 3
output:
0
result:
ok answer is '0'
Test #5:
score: 0
Accepted
time: 1ms
memory: 3764kb
input:
1 1 1
output:
1
result:
ok answer is '1'
Test #6:
score: 0
Accepted
time: 1ms
memory: 3684kb
input:
2 1 4 4 7
output:
1
result:
ok answer is '1'
Test #7:
score: 0
Accepted
time: 1ms
memory: 3668kb
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: 1ms
memory: 3740kb
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: 355ms
memory: 3776kb
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: 3684kb
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: 27ms
memory: 3708kb
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: 15ms
memory: 3676kb
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: 1008ms
memory: 3808kb
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'