QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#725706 | #9118. Flip or Not | 11d10xy | RE | 0ms | 0kb | C++14 | 1.5kb | 2024-11-08 19:29:08 | 2024-11-08 19:29:09 |
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=t-1;i>=0;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: 0
Runtime Error
input:
5 00001 00111 3 1 2 3 2 3 5
output:
4 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...