QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#748362#9118. Flip or NotDaiRuiChen007WA 1ms3844kbC++171.5kb2024-11-14 20:09:592024-11-14 20:09:59

Judging History

你现在查看的是最新测评结果

  • [2024-11-14 20:09:59]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3844kb
  • [2024-11-14 20:09:59]
  • 提交

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;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3844kb

input:

5
00001
00111
3
1 2 3
2
3 5

output:

4
001

result:

wrong answer invalid length of u: expected 4, found 3