Advertisement
newb_ie

Untitled

Oct 5th, 2021
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. vector<string> comb;
  5. int n;
  6.  
  7. void rec (int i,string s) {
  8. if (i == n) {
  9. comb.push_back(s);
  10. return;
  11. }
  12. rec(i + 1,s + '0');
  13. rec(i + 1,s + '1');
  14. }
  15.  
  16. int main () {
  17. ios::sync_with_stdio(false);
  18. cin.tie(nullptr);
  19. cout.tie(nullptr);
  20. string N;
  21. cin >> N;
  22. n = (int) N.size();
  23. rec(0,"");
  24. int64_t res = 0;
  25. for (string s : comb) {
  26. vector<int> x,y;
  27. for (int i = 0; i < n; ++i) {
  28. if (s[i] == '1') {
  29. x.push_back(N[i] - '0');
  30. } else {
  31. y.push_back(N[i] - '0');
  32. }
  33. }
  34. sort(x.rbegin(),x.rend());
  35. sort(y.rbegin(),y.rend());
  36. int64_t x1 = 0,y1 = 0;
  37. for (int i = 0; i < (int) x.size(); ++i) {
  38. x1 = x1 * 10 + x[i];
  39. }
  40. for (int i = 0; i < (int) y.size(); ++i) {
  41. y1 = y1 * 10 + y[i];
  42. }
  43. res = max(res,x1 * y1);
  44. }
  45. cout << res << '\n';
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement