QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#748367 | #9118. Flip or Not | DaiRuiChen007 | WA | 1ms | 3664kb | C++17 | 1.5kb | 2024-11-14 20:11:08 | 2024-11-14 20:11:09 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e4;
typedef bitset<N+5> poly;
inline int deg(const poly &u) {
for(int i=N;~i;--i) if(u[i]) return i;
return 0;
}
inline poly operator *(const poly &x,const poly &y) {
static poly z,o; z.reset();
for(int i=0;i<N;++i) if(y[i]) o=x,o<<=i,z^=o;
return z;
}
inline array<poly,2> divp(poly x,const poly &y) {
static poly z,o; z.reset();
int dy=deg(y);
for(int i=N-dy;~i;--i) if(x[i+dy]) z.set(i),o=y,o<<=i,x^=o;
return {z,x};
}
inline poly operator /(const poly &x,const poly &y) {
return divp(x,y)[0];
}
inline poly operator %(const poly &x,const poly &y) {
return divp(x,y)[1];
}
inline array<poly,2> exgcd(poly x,poly y) { //px+qy=g
poly p,q; p.set(0);
while(y.any()) {
auto z=divp(x,y);
p^=z[0]*q,swap(p,q);
x=y,y=z[1];
}
return {x,p};
}
void read1(poly &x) {
string s; cin>>s;
for(int i=0;i<(int)s.size();++i) if(s[i]=='1') x.set(i);
}
void read2(poly &x) {
int n; cin>>n;
for(int i;n--;) cin>>i,x.set(i-1);
}
signed main() {
ios::sync_with_stdio(false);
int n;
poly S,T,A,B;
cin>>n,read1(S),read1(T),read2(A),read2(B);
A.flip(0),A.flip(n);
auto rs=exgcd(B,A);
poly g=rs[0],q0=rs[1],gs=S%g,gt=T%g,vs=S*q0%A,vt=T*q0%A;
int d=deg(g);
for(int k=1;k<=N*5;++k) {
gs<<=1; if(gs[d]) gs^=g;
vs<<=1; if(vs[n]) vs^=A;
if(gs!=gt) continue;
poly q=vs^vt;
if(deg(q)-d<k) {
q=q/d,cout<<k<<"\n"; for(int i=k-1;~i;--i) cout<<q[i]; cout<<"\n";
return 0;
}
}
cout<<"-1\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3664kb
input:
5 00001 00111 3 1 2 3 2 3 5
output:
4 0010
result:
wrong answer f_s != f_t