QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#725708#9118. Flip or Not11d10xyWA 321ms4000kbC++141.5kb2024-11-08 19:29:482024-11-08 19:29:48

Judging History

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

  • [2024-11-08 19:29:48]
  • 评测
  • 测评结果:WA
  • 用时:321ms
  • 内存:4000kb
  • [2024-11-08 19:29:48]
  • 提交

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&&deg(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: 100
Accepted
time: 1ms
memory: 3992kb

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: 253ms
memory: 3744kb

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: 3808kb

input:

1
0
1
1
1
1
1

output:

1
1

result:

ok output is valid

Test #4:

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

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: 251ms
memory: 3860kb

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: 315ms
memory: 3880kb

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: 3868kb

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: 0ms
memory: 4000kb

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: 0ms
memory: 3848kb

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: 321ms
memory: 3792kb

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: 0ms
memory: 3952kb

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: 0ms
memory: 3924kb

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: 203ms
memory: 3820kb

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: 3932kb

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: 3924kb

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: 3992kb

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: 0ms
memory: 3956kb

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: 3928kb

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: 4000kb

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: 3860kb

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: 3932kb

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: 0ms
memory: 3816kb

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: 0ms
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: 299ms
memory: 3872kb

input:

1910
0100011011011000010100001001000111111011010010111110101110001001010100001011001110011000000100011000111011010100011000101111100110011110001111000011100110001011010101011001010001001001011001110100101100010110111100110101110101101010110011100101101000001111100000000011110011100110101000101011000...

output:

-1

result:

ok output is valid

Test #25:

score: 0
Accepted
time: 28ms
memory: 3948kb

input:

4123
1000001000000011111010101100100111001110111010001100010000000111101101101101011101100001110011111011101010011001011010010101100110100101110100101100110110110101000100011110111100111101010110001000110000101110011001111011011101111011100101111101000111011110110011110000111000001011000011111101000...

output:

4122
0011010000011100001001110010000111111010101011000100100111101010010111100010010100010001111100110000011011011000011111001010110000011011001110011101001000001100011011000001001101111100101101100010100101001101011010111001001111100111110000111010110100100000011000100000000010000100101110011010010...

result:

ok output is valid

Test #26:

score: 0
Accepted
time: 32ms
memory: 3944kb

input:

4474
1011011010101101101000001000000111010011100001101010100010100111111100011101001000010010010110000101010011100001010001011111101111110011011000011001101110010111110100111011010100101100001111101111111010000110001010110001111111011000110100101100000111110000110011010010001100110110011100010011100...

output:

4471
1100101001110000010101100100100011000101000000110010110011111111111111000000110001110101100111011110110111101100001100110011100000100000110100111110111011011111111001110101111010010100100100111110100000000011000001011100101100110101100000111100010010111010001011001101101001001000110111101111000...

result:

ok output is valid

Test #27:

score: 0
Accepted
time: 17ms
memory: 3992kb

input:

2514
0010101111011001011010111000011011011000001001110001111100011100100110111110101000000100011011000110010011011100010000110000101001000110000010110011011100001010101011100100011010011111011011100111011111111100011110001000000000110100001000111110111101010100110010000001001101000100101001110111111...

output:

2513
0001010100001010010010011011101010110011010111100010000101010100000111010101001011001111101000100101001011010100101101000101011111110001000101010001110100011101011100000100000101111110111010110101000111010110111011011000110000001001001101110000111110010001000011000010010101100001101111100110001...

result:

ok output is valid

Test #28:

score: 0
Accepted
time: 35ms
memory: 3932kb

input:

4813
0010010010001011101101000111110101101010100111111010001000001010011010110111000100101100010001110010100101010011111010001111110001110011010010111000111110001011011100111010110101100000101000110001010110111011000101011001000111000001011000000010111011010001101001011010001011100010010011011101101...

output:

4817
0000000010011000110101000011101011011101100110100111011101000111001000000110101111111111000010101011100010101010101110110101111010100001011111110000010100110100000101010101110001011001111100001000110111011111101000000101010111001110111000101100000001111001101110011001100100101001110110110111101...

result:

ok output is valid

Test #29:

score: 0
Accepted
time: 310ms
memory: 3924kb

input:

4352
0011111100110101100101000100100010000111101010000100001011111110011101011011001001110110001111011101101101010011111011011000101010100011110011010001011100111110111001010010101100111011111101011000101011011100101011010100000011110000010000100001000111101100001101101010000100110100101000111100100...

output:

-1

result:

ok output is valid

Test #30:

score: 0
Accepted
time: 290ms
memory: 3844kb

input:

3281
0010001100110001110100111011111010111010011010100011101101001000011001110010100000000000001110110001110101110001001011110101010110010100100110111010011100100010010101010111011110011000001011100111111110001010011101000001000011111110001001011101010000101101100011000110100011101011001010010011010...

output:

-1

result:

ok output is valid

Test #31:

score: 0
Accepted
time: 285ms
memory: 3884kb

input:

3520
1101100010110110001010100100011100001100001100010100101111111000010100011001110010110110001000101110011101001100010110001001101000101101110110010011100100001011011011111011000000100111111110111110111111110100001001011101111010100101100110011010001001001001101100011010000110101100111101111111010...

output:

-1

result:

ok output is valid

Test #32:

score: 0
Accepted
time: 295ms
memory: 3864kb

input:

3051
1011110101011100000100011100010100000011110001010011011011001111100101001000111101110011111000000001101010000100010100000110000011111101010000010111001011000001111111000010001100100011011011001111000010010010100100001110010000000111111001010000010011011111000010101101011110011001101101001110010...

output:

-1

result:

ok output is valid

Test #33:

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

input:

226
1001011011001011001110011000001000001101110110101110001111100011100001101011111100011011000110001100000000110010110100111101110101001001010001110010101101101100101000101010100010001100101100111111010100111010010010010111011001
011100010011011111111011001101001110101010001011111101000100010010001...

output:

-1

result:

ok output is valid

Test #34:

score: -100
Wrong Answer
time: 19ms
memory: 3988kb

input:

3346
1010101010011101100001001100100101101000110010100010110100011001100100101111100011000111111101010011010100000011101110010111110111011011011001100001001000011001001001010001010001111110100100010100001011010011011001101000001110101010100100011100110011111100110010010100101110011010011000101000100...

output:

40284
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

result:

wrong answer f_s != f_t