QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#725702 | #9118. Flip or Not | 11d10xy | WA | 317ms | 3992kb | C++14 | 1.5kb | 2024-11-08 19:27:33 | 2024-11-08 19:27:34 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using poly=bitset<10010>;
int n;
char buf[5010];
poly A,B,S,T;
inline int deg(poly f){
int w=n;
for(;w>=0&&!f[w];w--);
return w;
}
poly mul(poly f,poly g){
poly h;
for(int i=0;i<=n;i++)if(g[i])h^=f<<i;
return h;
}
pair<poly,poly>div(poly f,poly m){
int w=deg(m);
poly res;
for(int i=10000;i>=w;i--)if(f[i]){
res.set(i-w),f^=m<<i-w;
}
return{res,f};
}
pair<poly,poly>exgcd(poly w,poly m){
poly x(1),y;
while(m.any()){
auto o=div(w,m);
x^=mul(y,o.first),swap(x,y);
w=m,m=o.second;
}
return{w,x};
}
void init(){
scanf("%d",&n);
scanf("%s",buf);for(int i=0;i<n;i++)S.set(i,buf[i]-'0');
scanf("%s",buf);for(int i=0;i<n;i++)T.set(i,buf[i]-'0');
int P;scanf("%d",&P);
for(int x;P--;){
scanf("%d",&x),A.set(x-1);
}A.flip(0),A.set(n);
int Q;scanf("%d",&Q);
for(int x;Q--;){
scanf("%d",&x),B.set(x-1);
}
}
int main(){
init();
auto X=exgcd(B,A);
poly d=X.first,g=X.second;
int dn=deg(d);
poly w10=div(T,d).second,w1=div(S,d).second,w2=div(mul(S,g),A).second,w20=div(mul(g,T),A).second;
for(int t=1;t<=1000000;t++){
w1<<=1;
if(w1[dn])w1^=d;
w2<<=1;
if(w2[n])w2^=A;
poly q=w20^w2;
if(w1==w10&°(q)-dn<t){
poly ans=div(q,d).first;
printf("%d\n",t);
for(int i=0;i<t;i++)putchar(ans[i]+'0');
return 0;
}
}
printf("-1");
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3904kb
input:
5 00001 00111 3 1 2 3 2 3 5
output:
4 1001
result:
ok output is valid
Test #2:
score: 0
Accepted
time: 260ms
memory: 3924kb
input:
4 0110 1000 2 1 2 4 1 2 3 4
output:
-1
result:
ok output is valid
Test #3:
score: 0
Accepted
time: 0ms
memory: 3988kb
input:
1 0 1 1 1 1 1
output:
1 1
result:
ok output is valid
Test #4:
score: 0
Accepted
time: 0ms
memory: 3992kb
input:
8 11110000 10101011 6 2 3 5 6 7 8 3 4 7 8
output:
5 01110
result:
ok output is valid
Test #5:
score: 0
Accepted
time: 244ms
memory: 3836kb
input:
8 00010010 11000111 3 1 4 5 4 2 4 6 8
output:
-1
result:
ok output is valid
Test #6:
score: 0
Accepted
time: 317ms
memory: 3732kb
input:
8 00000111 10110100 6 3 4 5 6 7 8 4 1 3 7 8
output:
-1
result:
ok output is valid
Test #7:
score: -100
Wrong Answer
time: 0ms
memory: 3812kb
input:
8 00101100 11100111 3 1 2 6 6 1 3 4 5 7 8
output:
8 11100101
result:
wrong answer f_s != f_t