fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. map<string, pair<long long, int>> mp;
  4. map<string, bool> pick;
  5.  
  6. signed main(){
  7. cin.tie(0);
  8. ios::sync_with_stdio(false);
  9. int n, f;
  10. cin >> n >> f;
  11. string s;
  12. cin >> s;
  13. set<string> st;
  14. for(int x = 0; x < s.length() - 2; x++){
  15. string s1 = s.substr(x, 3);
  16. if((s1[0] != s1[1] && s1[0] != s1[2]) && s1[1] == s1[2]){
  17. mp[s1].first++;
  18. mp[s1].second = x;
  19. if(mp[s1].first >= f){
  20. st.insert(s1);
  21. }
  22. }
  23. for(int i = 0; i < 3; i++){
  24. s1 = s.substr(x, 3);
  25. for(int j = 0; j < 26; j++){
  26. s1[i] = char('a' + j);
  27. if((s1[0] == s1[1] || s1[0] == s1[2]) || s1[1] != s1[2]) continue;
  28. if(s1[0] == s1[2] || s1 == s.substr(x, 3) || pick[s1] || (x - mp[s1].second < 3 && mp[s1].first > 0)) continue;
  29.  
  30. pick[s1] = true;
  31. mp[s1].first++;
  32.  
  33. mp[s1].second = x;
  34. if(mp[s1].first >= f){
  35. st.insert(s1);
  36. }
  37. }
  38. }
  39.  
  40. }
  41. cout << st.size() << endl;
  42. for(string i: st){
  43. cout << i << endl;
  44. }
  45.  
  46. }
Success #stdin #stdout 0.01s 5280KB
stdin
10 2
zzmoozzmoo
stdout
2
moo
ozz