Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <cstdio>
- #include <cstring>
- #include <vector>
- #include <algorithm>
- #include <set>
- #include <map>
- #include <unordered_map>
- #include <unordered_set>
- #include <cmath>
- #include <ctime>
- #include <string>
- using namespace std;
- #ifdef LOCAL
- #define eprintf(...) fprintf(stderr, __VA_ARGS__)
- #else
- #define eprintf(...) 42
- #endif
- typedef long long ll;
- const int N = (int)1e3 + 10;
- char buf[N];
- int bits[N][N];
- bool used[N];
- int a[N];
- int getValue(char c)
- {
- if (c >= '0' && c <= '9')
- return c - '0';
- return c - 'a' + 10;
- }
- void putBits(int index, int pos, char c)
- {
- int value = getValue(c);
- for (int i = 0; i < 4; i++)
- {
- if (value & (1 << i))
- bits[index][pos + i] = 1;
- else
- bits[index][pos + i] = 0;
- }
- }
- void convertString(int index)
- {
- int len = strlen(buf);
- for (int i = 0; i < len; i++)
- {
- char c = buf[i];
- putBits(index, 4 * i, c);
- }
- }
- int main()
- {
- freopen ("filter.in", "r", stdin);
- freopen ("filter.out", "w", stdout);
- int m, f;
- scanf("%d%d", &m, &f);
- for (int i = 0; i < f; i++)
- scanf("%d", &a[i]);
- int n;
- scanf("%d", &n);
- for (int i = 0; i < n; i++)
- {
- scanf(" %s", buf);
- convertString(i);
- }
- int q;
- scanf("%d", &q);
- for (int i = 0; i < q; i++)
- {
- int id;
- scanf("%d", &id);
- for (int s = 0; s < n; s++)
- {
- if (used[s])
- continue;
- bool ok = false;
- for (int t = 0; t < f; t++)
- {
- ll x = ((ll)id * a[t]) % m;
- if (!bits[s][x])
- {
- ok = false;
- break;
- }
- }
- used[s] |= ok;
- }
- }
- int cnt = 0;
- for (int i = 0; i < n; i++)
- {
- if (used[i])
- cnt++;
- }
- printf("%d ", cnt);
- for (int i = 0; i < n; i++)
- if (used[i])
- printf("%d ", i);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement