Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.84 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define pb push_back
  5. #define F first
  6. #define S second
  7. #define ld long double
  8. #define ll long long
  9. #define TIME 1.0*clock()/CLOCKS_PER_SEC
  10.  
  11. mt19937 gen(chrono::system_clock::now().time_since_epoch().count());
  12.  
  13. const int N = 1e5 + 10;
  14. const ll MOD = 1e9 + 7;
  15. const int rx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
  16. const int ry[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
  17. const ld eps = 1e-7;
  18. const double pi = acos(-1.0);
  19. const int INF = 2e9;
  20.  
  21. int main() {
  22. #ifdef LOCAL
  23. freopen("input.txt", "r", stdin);
  24. freopen("output.txt", "w", stdout);
  25. #else
  26. // freopen("input.txt", "r", stdin);
  27. // freopen("output.txt", "w", stdout);
  28. #endif
  29. ios_base::sync_with_stdio(0);
  30. cin.tie(0);
  31. cout.tie(0);
  32. string s;
  33. cin >> s;
  34. vector <int> kol(10, 0);
  35. for (auto it : s) kol[int(it - '0')] ++;
  36. int n = s.size();
  37. vector <int> kol2(10, 0);
  38. if (kol[1] && kol[0] >= 18) {
  39. kol[1] --;
  40. kol[0] -= 18;
  41. kol2[1] ++;
  42. kol2[0] += 18;
  43. int sum = 0;
  44. for (int i = 0; i < 10; i++) {
  45. sum += kol[i];
  46. }
  47. if (sum == 0) {
  48. for (int i = 0; i < 10; i++) {
  49. if (kol2[i]) {
  50. kol2[i] --;
  51. kol[i] ++;
  52. sum ++;
  53. break;
  54. }
  55. }
  56. }
  57. } else {
  58. int len = 18;
  59. for (int i = 9; i >= 0; i--) {
  60. if (len < kol[i]) {
  61. kol[i] -= len;
  62. kol2[i] += len;
  63. len = 0;
  64. } else {
  65. kol2[i] += kol[i];
  66. len -= kol[i];
  67. kol[i] = 0;
  68. }
  69. }
  70. int sum = 0;
  71. for (int i = 0; i < 10; i++) {
  72. sum += kol[i];
  73. }
  74. if (sum == 0) {
  75. for (int i = 0; i < 10; i++) {
  76. if (kol2[i]) {
  77. kol2[i] --;
  78. kol[i] ++;
  79. sum ++;
  80. break;
  81. }
  82. }
  83. }
  84. if (sum == kol[0] && sum > 1) {
  85. kol2[0] ++;
  86. kol[0] --;
  87. sum --;
  88. bool f = false;
  89. for (int i = 1; i < 10; i++) {
  90. if (kol2[i]) {
  91. kol2[i] --;
  92. kol[i] ++;
  93. sum ++;
  94. f = true;
  95. break;
  96. }
  97. }
  98. if (!f) {
  99. cout << "-1 -1" << endl;
  100. return 0;
  101. }
  102. }
  103. }
  104. int len1 = 0, len2 = 0;
  105. for (int i = 0; i < 10; i++) len1 += kol[i];
  106. for (int i = 0; i < 10; i++) len2 += kol2[i];
  107. if ((len2 > 1 && len2 == kol2[0]) || !len1) {
  108. cout << "-1 -1" << endl;
  109. return 0;
  110. }
  111. if ((len1 > 1 && len1 == kol[0]) || !len2) {
  112. cout << "-1 -1" << endl;
  113. return 0;
  114. }
  115. if ((len1 <= 18 || (len1 == 19 && kol[1] == 1 && kol[0] == 18)) && (len2 <= 18 || (len2 == 19 && kol2[1] == 1 && kol2[0] == 18))) {
  116. for (int i = 1; i < 10; i++) {
  117. if (kol[i]) {
  118. cout << i;
  119. kol[i] --;
  120. break;
  121. }
  122. }
  123. for (int i = 0; i < kol[0]; i++) cout << "0";
  124. for (int i = 1; i < 10; i++) {
  125. for (int j = 0; j < kol[i]; j ++) cout << i;
  126. }
  127. cout << " ";
  128. for (int i = 1; i < 10; i++) {
  129. if (kol2[i]) {
  130. cout << i;
  131. kol2[i] --;
  132. break;
  133. }
  134. }
  135. for (int i = 0; i < kol2[0]; i++) cout << "0";
  136. for (int i = 1; i < 10; i++) {
  137. for (int j = 0; j < kol2[i]; j ++) cout << i;
  138. }
  139. cout << endl;
  140. } else cout << "-1 -1" << endl;
  141. return 0;
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement