Advertisement
Guest User

Untitled

a guest
May 25th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int N,M,i,j,x,che,K,len;
  4. string s;
  5. set<int>myset;
  6. map<int,int>mem;
  7. int main(){
  8. scanf("%d%d",&N,&M);
  9. for(i = 0 ; i < N ; i++){
  10. cin >> s;
  11. che = 0;
  12. for(j = 0 ; j < M ; j++){
  13. x = s[j]-'0';
  14. if(x) che |= 1 << (M-j-1);
  15. }
  16. mem[che] = i+1;
  17. }
  18. scanf("%d",&K);
  19. while(K--){
  20. scanf("%d",&len);
  21. bool found = false;
  22. cin >> s;
  23. che = 0;
  24. for(i = 0 ; i < len ; i++){
  25. if(i < M &&s[i]-'0'!=0) che |= 1 << (M-i-1);
  26. else if(i >= M) {
  27. che &= ~(1<<M-1);
  28. che = che << 1;
  29. che |= s[i]-'0';
  30. }
  31. if(mem[che] && i >= M-1) found = true,myset.insert(mem[che]);
  32. // printf("i = %d che = %d\n",i,che);
  33. }
  34. if(!found) printf("OK\n");
  35. else {
  36. for(auto i : myset) printf("%d ",i);
  37. printf("\n");
  38. myset.clear();
  39. }
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement