fork download
  1. #include<bits/stdc++.h>
  2. #include<iostream>
  3. #define ll long long
  4. using namespace std;
  5. int n, m, k, x, j, i, t[502], vt[502];
  6. string s, st[501], a;
  7. int main()
  8. {
  9. cin >> n >> m >> k >> x;
  10. cin >> s;
  11. for (i = 1; i <= m; i++)
  12. {
  13. cin >> a;
  14. sort(a.begin(), a.end());
  15. for (j = 0; j < a.size(); j++)
  16. if (a[j] != a[j + 1]) st[i] += a[j];
  17. // cout<<st[i]<<" ";
  18. }
  19. t[m + 1] = 1;
  20. for (i = m; i >= 1; i--)
  21. {
  22. t[i] = t[i + 1] * st[i].size();
  23. }
  24. // for (i=1;i<=m+1;i++)cout<<t[i]<<" ";
  25. // cout<<endl;
  26. if (t[1] == x)
  27. {
  28. for (i = 1; i <= m; i++) vt[i] = st[i].size();
  29. }
  30. else
  31. {
  32. i = 1;
  33. while (x > 0)
  34. {
  35. if (x >= t[i + 1])
  36. {
  37. vt[i] = x / t[i + 1];
  38. if (x % t[i + 1] != 0)
  39. {
  40. x = x % t[i + 1];
  41. vt[i]++;
  42. }
  43. else
  44. {
  45. for (j = i + 1; j <= m; j++) vt[j] = st[j].size();
  46. x = 0;
  47. }
  48. }
  49. else vt[i] = 1;
  50. i++;
  51. }
  52. }
  53. int d = 0;
  54. for (i = 0; i < s.size(); ++i) {
  55. if (s[i] == '#') {
  56. ++d;
  57. s[i] = st[d][vt[d] - 1];
  58. }
  59. }
  60. cout << s;
  61. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
Standard output is empty