fork download
  1. #include <bits/stdc++.h>
  2. #define endl '\n'
  3. #define ll long long
  4. using namespace std;
  5. const int N = 2e2;
  6.  
  7. int m, n, k, z, position, cnt;
  8. string x, y, a[N + 7];
  9. set <string> v;
  10. map <string, int> mp;
  11. void recur(int pos, string sub)
  12. {
  13. if(sub.size() > n) return;
  14. if(pos == x.size())
  15. {
  16. if(sub.size() < n) return;
  17. if(sub.size() == n)
  18. {
  19. int j = 0;
  20. for(int i = 0; i < y.size() && j < sub.size(); ++i)
  21. if(y[i] == sub[j]) ++j;
  22. if(j < sub.size())
  23. v.insert(sub);
  24. }
  25. return;
  26. }
  27.  
  28. recur(pos + 1, sub);
  29. recur(pos + 1, sub + x[pos]);
  30. }
  31.  
  32. int main()
  33. {
  34. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  35. cin >> m >> n >> k;
  36. cin >> x >> y;
  37. for(int i = 1; i <= m; i++) cin >> a[i];
  38. recur(0, "");
  39.  
  40. for(string tmp : v)
  41. mp[tmp] = ++cnt;
  42.  
  43. for(int i = 1; i <= m; ++i)
  44. {
  45. if(!mp.count(a[i])) cout << -1 << endl;
  46. else cout << mp[a[i]] % k << endl;
  47. }
  48. }
  49.  
Success #stdin #stdout 0.01s 5296KB
stdin
3 2 100
abab
abb
aa
ab
ba
stdout
1
-1
2