QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#455660 | #1262. Justice For Everyone | Kevin5307 | AC ✓ | 173ms | 11868kb | C++23 | 3.1kb | 2024-06-26 17:21:15 | 2024-06-26 17:21:15 |
Judging History
answer
//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
const ll mod=998244353,g=3;
ll ksm(ll a,ll b)
{
ll ans=1;
while(b)
{
if(b&1) ans=ans*a%mod;
b>>=1;
a=a*a%mod;
}
return ans;
}
void ntt(ll *a,int len,bool t)
{
vector<int> rev(len);
for(int i=0;i<len;i++)
rev[i]=(rev[i>>1]>>1)|((i&1)*(len>>1));
for(int i=0;i<len;i++)
if(rev[i]<i)
swap(a[i],a[rev[i]]);
for(int i=1;i<len;i<<=1)
{
ll gn=ksm(!t?3:ksm(3,mod-2),(mod-1)/i/2);
for(int j=0;j<len;j+=(i<<1))
{
ll g0=1;
for(int k=0;k<i;k++,g0=g0*gn%mod)
{
ll x=a[j+k],y=g0*a[i+j+k]%mod;
a[j+k]=(x+y)%mod;
a[i+j+k]=(x+mod-y)%mod;
}
}
}
if(t)
for(int i=0;i<len;i++)
a[i]=a[i]*ksm(len,mod-2)%mod;
}
int n;
ll val[202][4096];
ll fact[100100],rfact[100100];
ll det(vector<vector<ll>> A)
{
int n=sz(A);
ll ans=1;
for(int i=0;i<n;i++)
{
if(!A[i][i])
for(int j=i+1;j<n;j++)
if(A[j][i])
{
for(int k=0;k<n;k++)
swap(A[j][k],A[i][k]);
ans=(mod-ans)%mod;
break;
}
if(A[i][i])
{
ll value=ksm(A[i][i],mod-2);
ans=ans*A[i][i]%mod;
for(int j=0;j<n;j++)
A[i][j]=A[i][j]*value%mod;
for(int j=i+1;j<n;j++)
{
ll X=A[j][i];
for(int k=0;k<n;k++)
A[j][k]=(A[j][k]-X*A[i][k]%mod+mod)%mod;
}
}
else ans=0;
}
return ans;
}
ll res[4096];
int a[32],b[32];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
fact[0]=1;
for(int i=1;i<100100;i++)
fact[i]=fact[i-1]*i%mod;
for(int i=0;i<100100;i++)
rfact[i]=ksm(fact[i],mod-2);
cin>>n;
for(int i=0;i<n;i++)
cin>>a[i];
for(int i=0;i<n;i++)
cin>>b[i];
vector<pii> va,vb;
for(int i=0;i<n;i++)
{
va.pb(a[i],i);
vb.pb(b[i],i);
}
srt(va);
srt(vb);
for(int i=0;i<n;i++)
if(va[i].second!=vb[i].second)
die("0");
sort(a,a+n);
sort(b,b+n);
for(int i=0;i<=200;i++)
{
for(int j=0;j+j<=i;j++)
if(j&1)
val[i][j]=(mod-rfact[j]*rfact[i-j-j]%mod)%mod;
else
val[i][j]=rfact[j]*rfact[i-j-j]%mod;
ntt(val[i],4096,0);
}
for(int i=0;i<4096;i++)
{
vector<vector<ll>> M(n,vector<ll>(n));
for(int x=0;x<n;x++)
for(int y=0;y<n;y++)
if(a[x]>b[y])
M[x][y]=0;
else
M[x][y]=val[b[y]-a[x]][i];
res[i]=det(M);
}
ntt(res,4096,1);
ll ans=0;
int x=accumulate(b,b+n,0)-accumulate(a,a+n,0);
if(x&1) die("0");
for(int i=0;i+i<=x;i++)
ans=(ans+res[i]*fact[x-i-i]%mod*fact[x/2]%mod*rfact[x/2-i])%mod;
cout<<ans*ksm(ksm(2,mod-2),x/2)%mod<<endl;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 41ms
memory: 11636kb
input:
3 1 2 3 3 4 5
output:
1
result:
ok answer is '1'
Test #2:
score: 0
Accepted
time: 38ms
memory: 11632kb
input:
3 1 2 3 7 8 9
output:
42
result:
ok answer is '42'
Test #3:
score: 0
Accepted
time: 37ms
memory: 11788kb
input:
3 1 4 7 3 6 9
output:
6
result:
ok answer is '6'
Test #4:
score: 0
Accepted
time: 43ms
memory: 11668kb
input:
1 1 3
output:
0
result:
ok answer is '0'
Test #5:
score: 0
Accepted
time: 35ms
memory: 11556kb
input:
1 1 1
output:
1
result:
ok answer is '1'
Test #6:
score: 0
Accepted
time: 43ms
memory: 11488kb
input:
2 1 4 4 7
output:
1
result:
ok answer is '1'
Test #7:
score: 0
Accepted
time: 12ms
memory: 6016kb
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: 173ms
memory: 11868kb
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: 168ms
memory: 11528kb
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: 171ms
memory: 11620kb
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: 169ms
memory: 11804kb
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: 41ms
memory: 11752kb
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: 169ms
memory: 11652kb
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'