ProgMe

Untitled

Mar 29th, 2020
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.45 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define int int64_t
  3.  
  4. using namespace std;
  5.  
  6. bool prov(map <int, int> cnt, string s)
  7. {
  8. if (s.size() == 1 || s.size() > 38 || (cnt [0] == s.size() && s.size() > 2) || (s.size() == 38 && !(cnt [0] == 36 && cnt [1] == 2)) || (s.size() > 20 && cnt [0] == s.size() - 1) || (s.size() == 37 && !(cnt [0] >= 18 && cnt [1] >= 1)) || (s.size() == 20 && cnt [0] >= 18 && cnt [1] == 0))
  9. return 0;
  10. else
  11. return 1;
  12. }
  13.  
  14. int32_t main()
  15. {
  16. string s;
  17. cin >> s;
  18. map <int, int> cnt;
  19. for (auto i: s)
  20. cnt [i - '0']++;
  21. if (prov (cnt, s))
  22. {
  23. sort(s.begin(), s.end());
  24. deque <int> ans;
  25. for (auto i: s)
  26. ans.push_back(i - '0');
  27. if (ans.size() == 2)
  28. cout << ans [0] << " " << ans [1];
  29. else if (ans.size() < 20)
  30. {
  31. cout << ans.front() << " ";
  32. ans.pop_front();
  33. int i = 0;
  34. while (ans [i] == 0)
  35. i++;
  36. cout << ans [i];
  37. ans.erase(ans.begin() + i);
  38. for (auto i: ans)
  39. cout << i;
  40. }
  41. else if (ans.size() == 20)
  42. {
  43. if (cnt [0] >= 18 && cnt [1] >= 1)
  44. {
  45. cnt [1]--;
  46. cnt [0] -= 18;
  47. for (int i = 0; i <= 9; i++)
  48. {
  49. if (cnt [i] > 0)
  50. {
  51. cout << i << " ";
  52. break;
  53. }
  54. }
  55. cout << 1000000000000000000;
  56. }
  57. else
  58. {
  59. int i = 0;
  60. while (ans [i] == 0)
  61. i++;
  62. cout << ans [i];
  63. ans.erase(ans.begin() + i);
  64. while (ans.size() > 18)
  65. {
  66. cout << ans.front();
  67. ans.pop_front();
  68. }
  69. cout << " ";
  70. i = 0;
  71. while (ans [i] == 0)
  72. i++;
  73. cout << ans [i];
  74. ans.erase(ans.begin() + i);
  75. for (auto i: ans)
  76. cout << i;
  77. }
  78. }
  79. else if (ans.size() < 37)
  80. {
  81. int i = 0;
  82. while (ans [i] == 0)
  83. i++;
  84. cout << ans [i];
  85. ans.erase(ans.begin() + i);
  86. while (ans.size() > 18)
  87. {
  88. cout << ans.front();
  89. ans.pop_front();
  90. }
  91. cout << " ";
  92. i = 0;
  93. while (ans [i] == 0)
  94. i++;
  95. cout << ans [i];
  96. ans.erase(ans.begin() + i);
  97. for (auto i: ans)
  98. cout << i;
  99. }
  100. else if (ans.size() == 37)
  101. {
  102. int j = 18;
  103. while (j--)
  104. ans.pop_front();
  105. while (ans [j] == 0)
  106. j++;
  107. ans.erase(ans.begin() + j);
  108. int i = 0;
  109. while (ans [i] == 0)
  110. i++;
  111. cout << ans [i];
  112. ans.erase(ans.begin() + i);
  113. for (auto i: ans)
  114. cout << i;
  115. cout << " ";
  116. cout << 1000000000000000000;
  117. }
  118. else
  119. {
  120. cout << 1000000000000000000 << " " << 1000000000000000000;
  121. }
  122. }
  123. else
  124. cout << "-1 -1";
  125. }
Advertisement
Add Comment
Please, Sign In to add comment