Advertisement
Guest User

Untitled

a guest
Dec 21st, 2014
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.76 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <cstdio>
  4. #include <cstring>
  5. #include <vector>
  6. #include <algorithm>
  7. #include <set>
  8. #include <map>
  9. #include <unordered_map>
  10. #include <unordered_set>
  11. #include <cmath>
  12. #include <ctime>
  13. #include <string>
  14. using namespace std;
  15.  
  16. #ifdef LOCAL
  17.     #define eprintf(...) fprintf(stderr, __VA_ARGS__)
  18. #else
  19.     #define eprintf(...) 42
  20. #endif
  21.  
  22. typedef long long ll;
  23. const int N = (int)1e3 + 10;
  24. char buf[N];
  25. int bits[N][N];
  26. bool used[N];
  27. int a[N];
  28.  
  29. int getValue(char c)
  30. {
  31.     if (c >= '0' && c <= '9')
  32.         return c - '0';
  33.     return c - 'a' + 10;
  34. }
  35.  
  36. void putBits(int index, int pos, char c)
  37. {
  38.     int value = getValue(c);
  39.     for (int i = 0; i < 4; i++)
  40.     {
  41.         if (value & (1 << i))
  42.             bits[index][pos + i] = 1;
  43.         else
  44.             bits[index][pos + i] = 0;
  45.     }
  46. }
  47.  
  48. void convertString(int index)
  49. {
  50.     int len = strlen(buf);
  51.     for (int i = 0; i < len; i++)
  52.     {
  53.         char c = buf[i];
  54.         putBits(index, 4 * i, c);
  55.     }
  56. }
  57.  
  58. int main()
  59. {
  60.     freopen ("filter.in", "r", stdin);
  61.     freopen ("filter.out", "w", stdout);
  62.  
  63.     int m, f;
  64.     scanf("%d%d", &m, &f);
  65.     for (int i = 0; i < f; i++)
  66.         scanf("%d", &a[i]);
  67.  
  68.     int n;
  69.     scanf("%d", &n);
  70.     for (int i = 0; i < n; i++)
  71.     {
  72.         scanf(" %s", buf);
  73.         convertString(i);
  74.     }
  75.  
  76.     int q;
  77.     scanf("%d", &q);
  78.     for (int i = 0; i < q; i++)
  79.     {
  80.         int id;
  81.         scanf("%d", &id);
  82.         for (int s = 0; s < n; s++)
  83.         {
  84.             if (used[s])
  85.                 continue;
  86.             bool ok = false;
  87.             for (int t = 0; t < f; t++)
  88.             {
  89.                 ll x = ((ll)id * a[t]) % m;
  90.                 if (!bits[s][x])
  91.                 {
  92.                     ok = false;
  93.                     break;
  94.                 }
  95.             }
  96.             used[s] |= ok;
  97.         }
  98.     }
  99.     int cnt = 0;
  100.     for (int i = 0; i < n; i++)
  101.     {
  102.         if (used[i])
  103.             cnt++;
  104.     }
  105.     printf("%d ", cnt);
  106.     for (int i = 0; i < n; i++)
  107.         if (used[i])
  108.             printf("%d ", i);
  109.  
  110.     return 0;
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement