ProgMe

Untitled

Apr 5th, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define int int64_t
  3.  
  4. using namespace std;
  5.  
  6. string update (string s)
  7. {
  8. if (s == "1")
  9. return "11";
  10. int l = 1;
  11. bool b = 0;
  12. string s1;
  13. for (int i = 1; i < s.size(); i++)
  14. {
  15. if (s [i] == s [i - 1])
  16. {
  17. if (b == 0)
  18. {
  19. b = 1;
  20. l++;
  21. }
  22. else
  23. l++;
  24. }
  25. else
  26. {
  27. s1 += to_string(l);
  28. s1 += s [i - 1];
  29. l = 1;
  30. }
  31. }
  32. s1 += to_string(l);
  33. s1 += s.back();
  34. return s1;
  35. }
  36.  
  37. string fix(string s, int m)
  38. {
  39. if (m >= s.size())
  40. return s;
  41. else
  42. return s.substr(s.size() - m, s.size());
  43. }
  44.  
  45. int32_t main()
  46. {
  47. int n, m, k = 1;
  48. cin >> n >> m;
  49. string s = "1";
  50. while (k < n && s.size() < m)
  51. {
  52. s = update(s);
  53. k++;
  54. }
  55. while (k % 4 != n % 4)
  56. {
  57. s = update(s);
  58. k++;
  59. }
  60. cout << fix(s, m);
  61. }
Advertisement
Add Comment
Please, Sign In to add comment