SHARE
TWEET

Untitled

a guest May 25th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int k,m,q;
  4. int i,j,c;
  5. unordered_map <int,int> mp;
  6. unordered_map <string,bool> visit;
  7. set <int> s,s1;
  8. string t;
  9. int main(){
  10.     scanf("%d%d",&k,&m);
  11.     for (i = 0; i < k; i++){
  12.         c = 0;
  13.         cin >> t;
  14.         for (j = 0; j < m; j++) if (t[j] == '1') c |= 1 << (m-j-1);
  15.         mp[c] = i;
  16.         s.insert(c);
  17.     }
  18.     scanf("%d",&q);
  19.     for (i = 0; i < q; i++){
  20.         s1.clear();
  21.         c = 0;
  22.         scanf("%d",&k);
  23.         cin >> t;
  24.         if (visit[t]) continue;
  25.         visit[t] = true;
  26.         for (j = 0; j < m; j++)
  27.             if (t[j] == '1') c |= 1 << (m-j-1);
  28.        
  29.         for ( ; j <= k; j++){
  30.             if (s.find(c) != s.end()) s1.insert(c);
  31.             if (j == k) continue;
  32.             c = (c<<1)&((1<<m)-1);
  33.             if (t[j] == '1') c |= (1<<0);
  34.         }
  35.        
  36.         if (s1.empty()) printf("OK\n");
  37.         else{
  38.             c = 0;
  39.             for (auto c1 : s1) c |= 1 << mp[c1];
  40.                
  41.             for (j = 0; j < m; j++) if ((1<<j) & c) printf("%d ",j+1);
  42.             printf("\n");
  43.         }
  44.  
  45.     }
  46. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top