QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#748511#9118. Flip or NotDaiRuiChen007WA 660ms3896kbC++171.5kb2024-11-14 20:36:172024-11-14 20:36:17

Judging History

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

  • [2024-11-14 20:36:17]
  • 评测
  • 测评结果:WA
  • 用时:660ms
  • 内存:3896kb
  • [2024-11-14 20:36:17]
  • 提交

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/g;
			cout<<k<<"\n"; for(int i=k-1;~i;--i) cout<<(i<n&&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: 100
Accepted
time: 1ms
memory: 3584kb

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: 9ms
memory: 3644kb

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: 1ms
memory: 3892kb

input:

1
0
1
1
1
1
1

output:

1
1

result:

ok output is valid

Test #4:

score: 0
Accepted
time: 1ms
memory: 3584kb

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: 9ms
memory: 3560kb

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: 12ms
memory: 3536kb

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: 0
Accepted
time: 1ms
memory: 3896kb

input:

8
00101100
11100111
3
1 2 6
6
1 3 4 5 7 8

output:

8
10100111

result:

ok output is valid

Test #8:

score: 0
Accepted
time: 1ms
memory: 3584kb

input:

9
111001001
100001000
7
1 3 4 5 6 7 8
4
1 3 7 9

output:

2
01

result:

ok output is valid

Test #9:

score: 0
Accepted
time: 1ms
memory: 3520kb

input:

8
01100110
00000101
3
4 5 7
5
2 3 6 7 8

output:

13
0000000000000

result:

ok output is valid

Test #10:

score: 0
Accepted
time: 12ms
memory: 3664kb

input:

10
1001011001
0101100100
4
4 5 7 9
4
4 5 7 10

output:

-1

result:

ok output is valid

Test #11:

score: 0
Accepted
time: 1ms
memory: 3652kb

input:

7
1000010
1010101
4
3 4 5 6
4
1 2 4 5

output:

5
00110

result:

ok output is valid

Test #12:

score: 0
Accepted
time: 1ms
memory: 3536kb

input:

6
101011
101000
1
6
4
2 3 4 6

output:

2
11

result:

ok output is valid

Test #13:

score: 0
Accepted
time: 6ms
memory: 3648kb

input:

3
000
110
2
2 3
2
1 3

output:

-1

result:

ok output is valid

Test #14:

score: 0
Accepted
time: 1ms
memory: 3652kb

input:

19
1100010001111111100
0001101011001010110
10
2 3 4 5 6 7 9 14 15 19
10
3 5 6 8 10 11 12 17 18 19

output:

15
011001011010111

result:

ok output is valid

Test #15:

score: 0
Accepted
time: 0ms
memory: 3880kb

input:

7
0111111
0101011
6
2 3 4 5 6 7
4
1 3 5 7

output:

7
0000001

result:

ok output is valid

Test #16:

score: 0
Accepted
time: 1ms
memory: 3892kb

input:

17
10010100010100010
10101101101001101
8
3 5 8 9 12 14 15 17
8
1 3 5 8 10 12 14 15

output:

15
000001111100100

result:

ok output is valid

Test #17:

score: 0
Accepted
time: 1ms
memory: 3584kb

input:

13
1101000011011
1010001110110
4
3 5 6 13
8
2 3 4 7 8 10 11 13

output:

146
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010

result:

ok output is valid

Test #18:

score: 0
Accepted
time: 0ms
memory: 3624kb

input:

15
101011111011111
110110110101110
8
3 6 8 9 11 12 13 15
10
1 4 5 6 7 11 12 13 14 15

output:

13
0000010101111

result:

ok output is valid

Test #19:

score: 0
Accepted
time: 1ms
memory: 3584kb

input:

18
000000100100001110
011101100101001001
6
5 6 7 8 10 15
12
1 2 4 5 7 9 10 13 14 15 16 17

output:

13
1011100001110

result:

ok output is valid

Test #20:

score: 0
Accepted
time: 1ms
memory: 3896kb

input:

14
10111010011001
01010010010001
5
4 7 11 12 14
7
3 7 8 9 11 12 14

output:

485
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

result:

ok output is valid

Test #21:

score: 0
Accepted
time: 1ms
memory: 3584kb

input:

11
00011011101
00100111111
3
2 4 10
7
3 4 5 7 8 10 11

output:

11
00001001101

result:

ok output is valid

Test #22:

score: 0
Accepted
time: 1ms
memory: 3648kb

input:

8
00101000
01010101
4
2 6 7 8
4
1 3 4 6

output:

7
0010110

result:

ok output is valid

Test #23:

score: 0
Accepted
time: 1ms
memory: 3852kb

input:

15
100101100001100
001111110110000
10
2 4 5 6 7 8 9 12 14 15
6
3 6 9 10 13 14

output:

12
111010011101

result:

ok output is valid

Test #24:

score: 0
Accepted
time: 121ms
memory: 3600kb

input:

1910
0100011011011000010100001001000111111011010010111110101110001001010100001011001110011000000100011000111011010100011000101111100110011110001111000011100110001011010101011001010001001001011001110100101100010110111100110101110101101010110011100101101000001111100000000011110011100110101000101011000...

output:

-1

result:

ok output is valid

Test #25:

score: 0
Accepted
time: 479ms
memory: 3604kb

input:

4123
1000001000000011111010101100100111001110111010001100010000000111101101101101011101100001110011111011101010011001011010010101100110100101110100101100110110110101000100011110111100111101010110001000110000101110011001111011011101111011100101111101000111011110110011110000111000001011000011111101000...

output:

4122
0011010000011100001001110010000111111010101011000100100111101010010111100010010100010001111100110000011011011000011111001010110000011011001110011101001000001100011011000001001101111100101101100010100101001101011010111001001111100111110000111010110100100000011000100000000010000100101110011010010...

result:

ok output is valid

Test #26:

score: 0
Accepted
time: 560ms
memory: 3868kb

input:

4474
1011011010101101101000001000000111010011100001101010100010100111111100011101001000010010010110000101010011100001010001011111101111110011011000011001101110010111110100111011010100101100001111101111111010000110001010110001111111011000110100101100000111110000110011010010001100110110011100010011100...

output:

4471
1100101001110000010101100100100011000101000000110010110011111111111111000000110001110101100111011110110111101100001100110011100000100000110100111110111011011111111001110101111010010100100100111110100000000011000001011100101100110101100000111100010010111010001011001101101001001000110111101111000...

result:

ok output is valid

Test #27:

score: 0
Accepted
time: 206ms
memory: 3632kb

input:

2514
0010101111011001011010111000011011011000001001110001111100011100100110111110101000000100011011000110010011011100010000110000101001000110000010110011011100001010101011100100011010011111011011100111011111111100011110001000000000110100001000111110111101010100110010000001001101000100101001110111111...

output:

2513
0001010100001010010010011011101010110011010111100010000101010100000111010101001011001111101000100101001011010100101101000101011111110001000101010001110100011101011100000100000101111110111010110101000111010110111011011000110000001001001101110000111110010001000011000010010101100001101111100110001...

result:

ok output is valid

Test #28:

score: 0
Accepted
time: 660ms
memory: 3608kb

input:

4813
0010010010001011101101000111110101101010100111111010001000001010011010110111000100101100010001110010100101010011111010001111110001110011010010111000111110001011011100111010110101100000101000110001010110111011000101011001000111000001011000000010111011010001101001011010001011100010010011011101101...

output:

4817
0000000010011000110101000011101011011101100110100111011101000111001000000110101111111111000010101011100010101010101110110101111010100001011111110000010100110100000101010101110001011001111100001000110111011111101000000101010111001110111000101100000001111001101110011001100100101001110110110111101...

result:

ok output is valid

Test #29:

score: 0
Accepted
time: 431ms
memory: 3684kb

input:

4352
0011111100110101100101000100100010000111101010000100001011111110011101011011001001110110001111011101101101010011111011011000101010100011110011010001011100111110111001010010101100111011111101011000101011011100101011010100000011110000010000100001000111101100001101101010000100110100101000111100100...

output:

-1

result:

ok output is valid

Test #30:

score: 0
Accepted
time: 29ms
memory: 3832kb

input:

3281
0010001100110001110100111011111010111010011010100011101101001000011001110010100000000000001110110001110101110001001011110101010110010100100110111010011100100010010101010111011110011000001011100111111110001010011101000001000011111110001001011101010000101101100011000110100011101011001010010011010...

output:

-1

result:

ok output is valid

Test #31:

score: 0
Accepted
time: 24ms
memory: 3676kb

input:

3520
1101100010110110001010100100011100001100001100010100101111111000010100011001110010110110001000101110011101001100010110001001101000101101110110010011100100001011011011111011000000100111111110111110111111110100001001011101111010100101100110011010001001001001101100011010000110101100111101111111010...

output:

-1

result:

ok output is valid

Test #32:

score: 0
Accepted
time: 134ms
memory: 3608kb

input:

3051
1011110101011100000100011100010100000011110001010011011011001111100101001000111101110011111000000001101010000100010100000110000011111101010000010111001011000001111111000010001100100011011011001111000010010010100100001110010000000111111001010000010011011111000010101101011110011001101101001110010...

output:

-1

result:

ok output is valid

Test #33:

score: 0
Accepted
time: 11ms
memory: 3848kb

input:

226
1001011011001011001110011000001000001101110110101110001111100011100001101011111100011011000110001100000000110010110100111101110101001001010001110010101101101100101000101010100010001100101100111111010100111010010010010111011001
011100010011011111111011001101001110101010001011111101000100010010001...

output:

-1

result:

ok output is valid

Test #34:

score: 0
Accepted
time: 57ms
memory: 3660kb

input:

3346
1010101010011101100001001100100101101000110010100010110100011001100100101111100011000111111101010011010100000011101110010111110111011011011001100001001000011001001001010001010001111110100100010100001011010011011001101000001110101010100100011100110011111100110010010100101110011010011000101000100...

output:

40284
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

result:

ok output is valid

Test #35:

score: -100
Wrong Answer
time: 172ms
memory: 3676kb

input:

3512
1111001111010100101010010010001101000010110111001110010101001110010011111001010100111110100001001011100011011000111010000010111011111001101100101010010111000000001101011000101100101110000010101110000011111110001000110011001111111000110001100111101001011010001001000101001101110011011010111111110...

output:

-1

result:

wrong answer mismatched m: expected 107254, found -1