fork download
  1.  
  2. //|Art|
  3. #pragma GCC optimize("02,unroll-loops")
  4. #pragma GCC target("avx2,fma")
  5.  
  6. #include <iostream>
  7. #include <chrono>
  8. #include <algorithm>
  9.  
  10. //#include <bits/stdc++.h>
  11.  
  12. #define el cout << '\n'
  13. #define fi first
  14. #define se second
  15. #define pb push_back
  16. #define ll long long
  17. #define st string
  18. #define N 505
  19.  
  20. #define sz(x) (x).size()
  21. #define all(v) (v).begin(), (v).end()
  22. #define FOR(a,b,c) for(int a=b;a<=c;++a)
  23. #define FORE(a,b,c) for(int a=b;a>=c;--a)
  24. #define FED(a,b,c) for(int a=b;a<c;++a)
  25.  
  26. #define __Art__ signed main()
  27. #define NAME "Art"
  28.  
  29. using namespace std;
  30.  
  31. string a[N];
  32. st p;
  33. int n, m, k, x;
  34.  
  35. void cal (st s){
  36. if (sz(s) == m) {
  37. cout << x, el;
  38. --x;
  39. if (x == 0){
  40. int i = 0;
  41. for (char &x : p) {
  42. if (x == '#') cout << s[i], ++i;
  43. else cout << x;
  44. }
  45. return;
  46. }
  47. else if (x < 0) exit(0);
  48. }
  49. else FED (i, 0, k) cal(s + a[sz(s) + 1][i]);
  50. }
  51.  
  52. void sol(){
  53. cin >> n >> m >> k >> x;
  54. cin >> p;
  55. FOR (i, 1, m) cin >> a[i], sort(all(a[i]));
  56. cal("");
  57. }
  58.  
  59. __Art__{
  60.  
  61. if (fopen(NAME".INP", "r")) {
  62. freopen(NAME".INP", "r", stdin);
  63. freopen(NAME".OUT", "w", stdout);
  64. }
  65.  
  66. ios_base::sync_with_stdio(false);
  67. cin.tie(nullptr);
  68. cout.tie(nullptr);
  69.  
  70. sol();
  71.  
  72. return (0 ^ 0);
  73. }
  74.  
Success #stdin #stdout 0.01s 5280KB
stdin
13 3 2 3
#m#tpnkmkb#ld
ne
ju
og
stdout
3
2
1
emutpnkmkbgld0