Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- vector<string> comb;
- int n;
- void rec (int i,string s) {
- if (i == n) {
- comb.push_back(s);
- return;
- }
- rec(i + 1,s + '0');
- rec(i + 1,s + '1');
- }
- int main () {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- string N;
- cin >> N;
- n = (int) N.size();
- rec(0,"");
- int64_t res = 0;
- for (string s : comb) {
- vector<int> x,y;
- for (int i = 0; i < n; ++i) {
- if (s[i] == '1') {
- x.push_back(N[i] - '0');
- } else {
- y.push_back(N[i] - '0');
- }
- }
- sort(x.rbegin(),x.rend());
- sort(y.rbegin(),y.rend());
- int64_t x1 = 0,y1 = 0;
- for (int i = 0; i < (int) x.size(); ++i) {
- x1 = x1 * 10 + x[i];
- }
- for (int i = 0; i < (int) y.size(); ++i) {
- y1 = y1 * 10 + y[i];
- }
- res = max(res,x1 * y1);
- }
- cout << res << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement