Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define int int64_t
- using namespace std;
- bool prov(map <int, int> cnt, string s)
- {
- 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))
- return 0;
- else
- return 1;
- }
- int32_t main()
- {
- string s;
- cin >> s;
- map <int, int> cnt;
- for (auto i: s)
- cnt [i - '0']++;
- if (prov (cnt, s))
- {
- sort(s.begin(), s.end());
- deque <int> ans;
- for (auto i: s)
- ans.push_back(i - '0');
- if (ans.size() == 2)
- cout << ans [0] << " " << ans [1];
- else if (ans.size() < 20)
- {
- cout << ans.front() << " ";
- ans.pop_front();
- int i = 0;
- while (ans [i] == 0)
- i++;
- cout << ans [i];
- ans.erase(ans.begin() + i);
- for (auto i: ans)
- cout << i;
- }
- else if (ans.size() == 20)
- {
- if (cnt [0] >= 18 && cnt [1] >= 1)
- {
- cnt [1]--;
- cnt [0] -= 18;
- for (int i = 0; i <= 9; i++)
- {
- if (cnt [i] > 0)
- {
- cout << i << " ";
- break;
- }
- }
- cout << 1000000000000000000;
- }
- else
- {
- int i = 0;
- while (ans [i] == 0)
- i++;
- cout << ans [i];
- ans.erase(ans.begin() + i);
- while (ans.size() > 18)
- {
- cout << ans.front();
- ans.pop_front();
- }
- cout << " ";
- i = 0;
- while (ans [i] == 0)
- i++;
- cout << ans [i];
- ans.erase(ans.begin() + i);
- for (auto i: ans)
- cout << i;
- }
- }
- else if (ans.size() < 37)
- {
- int i = 0;
- while (ans [i] == 0)
- i++;
- cout << ans [i];
- ans.erase(ans.begin() + i);
- while (ans.size() > 18)
- {
- cout << ans.front();
- ans.pop_front();
- }
- cout << " ";
- i = 0;
- while (ans [i] == 0)
- i++;
- cout << ans [i];
- ans.erase(ans.begin() + i);
- for (auto i: ans)
- cout << i;
- }
- else if (ans.size() == 37)
- {
- int j = 18;
- while (j--)
- ans.pop_front();
- while (ans [j] == 0)
- j++;
- ans.erase(ans.begin() + j);
- int i = 0;
- while (ans [i] == 0)
- i++;
- cout << ans [i];
- ans.erase(ans.begin() + i);
- for (auto i: ans)
- cout << i;
- cout << " ";
- cout << 1000000000000000000;
- }
- else
- {
- cout << 1000000000000000000 << " " << 1000000000000000000;
- }
- }
- else
- cout << "-1 -1";
- }
Advertisement
Add Comment
Please, Sign In to add comment