QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#290518 | #2579. 开关 | MoRanSky | 100 ✓ | 18ms | 4632kb | C++23 | 1.5kb | 2023-12-25 05:16:18 | 2023-12-25 05:16:18 |
Judging History
answer
//xtqqwq
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef long long LL;
typedef pair<int,int>PII;
template<typename T>void inline read(T&x) {
x=0;int f=1;char s=getchar();
while (s<'0'||s>'9') { if (s=='-') { f=-1;} s=getchar();}
while (s>='0'&&s<='9') x=x*10+(s^48),s=getchar();
x*=f;
}
template<typename T>bool inline chkmin(T&x,T y) { return y<x ? x=y,1 : 0;}
template<typename T>bool inline chkmax(T&x,T y) { return y>x ? x=y,1 : 0;}
const int N=105,M=50005,P=998244353;
int n,a[N],p[N],f[2][M],g[2][M],m,ans;
int inline power(int a,int b) {
int ret=1;
while (b) {
if (b&1) ret=1ll*ret*a % P;
a=1ll*a*a % P;
b>>=1;
}
return ret;
}
void inline add(int&x,int y) {
x+=y;
if (x>=P) x-=P;
}
void inline del(int&x,int y) {
x-=y;
if (x<0) x+=P;
}
int main() {
read(n);
for (int i=1;i<=n;i++) read(a[i]);
for (int i=1;i<=n;i++) read(p[i]),m+=p[i];
f[0][0]=1;
for (int i=1;i<=n;i++) {
memcpy(g,f,sizeof g);
memset(f,0,sizeof f);
for (int x=0;x<=1;x++) {
for (int y=0;y<=m;y++) {
if (!g[x][y]) continue;
add(f[x^a[i]][y+p[i]],g[x][y]);
add(f[x][y],g[x][y]);
}
}
}
int I=power(m,P-2);
for (int y=1;y<=m;y++) {
if (!f[1][y]) continue;
int w=P-2;
int z=1;
add(z,1ll*y*I % P);
del(z,1ll*(m-y)*I % P);
w=1ll*w*power(z,P-2) % P;
del(ans,1ll*w*f[1][y] % P);
}
printf("%d\n",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 10
Accepted
time: 1ms
memory: 4496kb
input:
2 1 1 23723 26273
output:
877668810
result:
ok single line: '877668810'
Test #2:
score: 10
Accepted
time: 1ms
memory: 4624kb
input:
2 1 0 18216 31771
output:
489970511
result:
ok single line: '489970511'
Test #3:
score: 10
Accepted
time: 1ms
memory: 4620kb
input:
8 1 1 0 1 1 0 1 0 1270 10205 3901 3809 8931 2530 11580 7773
output:
193550909
result:
ok single line: '193550909'
Test #4:
score: 10
Accepted
time: 1ms
memory: 4624kb
input:
8 0 1 0 0 0 1 0 0 5929 4817 1939 5783 7039 5771 9785 8934
output:
662840715
result:
ok single line: '662840715'
Test #5:
score: 10
Accepted
time: 0ms
memory: 4628kb
input:
100 0 1 0 1 1 1 0 1 0 1 1 1 1 1 1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0 1 0 1 0 1 1 0 0 1 0 1 0 0 1 1 1 1 0 0 0 1 1 1 1 0 1 0 0 1 0 1 0 0 0 0 1 1 0 1 1 0 0 0 0 1 0 1 1 1 1 0 0 0 0 0 1 1 0 1 0 0 0 0 1 0 0 0 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
186395599
result:
ok single line: '186395599'
Test #6:
score: 10
Accepted
time: 2ms
memory: 4500kb
input:
100 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 2 2 1 2 1 1 2 1 2 1 2 1 2 1 2 2 1 1 1 1 1 2 2 2 2 2 1 2 1 1 1 2 1 1 1 2 2 1 2 2 1 2 ...
output:
507890478
result:
ok single line: '507890478'
Test #7:
score: 10
Accepted
time: 2ms
memory: 4592kb
input:
100 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 1 2 2 1 2 1 2 2 2 1 1 2 1 1 1 2 1 2 1 1 1 1 2 2 1 1 2 1 2 2 2 1 1 2 2 1 1 2 1 2 1 2 2 1 1 ...
output:
133411468
result:
ok single line: '133411468'
Test #8:
score: 10
Accepted
time: 3ms
memory: 4520kb
input:
100 0 1 0 1 0 0 1 0 1 1 1 0 0 0 1 0 1 1 0 0 1 1 0 0 1 1 1 0 1 0 0 1 0 0 0 0 0 0 1 0 1 1 0 0 1 0 1 1 1 0 1 1 1 0 1 1 1 1 1 1 0 1 1 0 1 1 0 1 0 0 1 1 0 1 0 0 0 0 1 0 0 0 0 0 0 1 0 1 1 0 0 1 1 0 0 0 1 1 0 0 24 28 18 19 22 36 35 24 7 19 26 2 31 20 33 11 20 37 11 36 9 28 16 20 46 28 5 20 40 27 13 15 28 7...
output:
988115696
result:
ok single line: '988115696'
Test #9:
score: 10
Accepted
time: 3ms
memory: 4632kb
input:
100 1 1 1 0 1 0 1 1 1 1 1 1 1 0 1 1 1 1 0 1 1 1 1 0 0 1 1 0 1 0 1 0 1 0 1 1 1 1 0 0 0 1 0 1 1 0 0 1 0 0 1 0 1 1 0 1 0 0 1 1 1 1 0 1 0 0 0 0 0 0 1 0 1 1 1 1 1 1 0 0 1 1 0 0 0 1 1 1 1 0 0 0 0 1 1 0 1 0 1 0 21 11 16 21 30 35 10 3 15 33 39 7 16 31 24 27 4 15 38 16 6 7 18 11 8 31 8 17 12 20 27 9 44 9 31 ...
output:
124960105
result:
ok single line: '124960105'
Test #10:
score: 10
Accepted
time: 18ms
memory: 4548kb
input:
100 1 0 0 1 0 1 0 0 1 1 1 0 0 1 0 0 0 1 1 1 1 0 1 1 1 1 0 1 0 0 1 0 1 1 1 0 0 0 1 1 1 0 1 1 1 1 0 1 0 1 0 1 1 1 0 1 1 1 1 1 0 1 1 0 1 0 1 0 0 0 0 1 1 1 0 0 1 0 1 1 1 1 0 0 0 0 0 1 0 0 1 1 1 0 1 0 1 1 1 1 840 587 741 540 310 84 284 345 368 251 545 676 754 274 266 97 858 486 108 727 373 283 722 539 29...
output:
114906083
result:
ok single line: '114906083'
Extra Test:
score: 0
Extra Test Passed