T3000

Untitled

Jun 1st, 2022
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using ll = long long;
  4. using ld = long double;
  5. using namespace std;
  6.  
  7. vector<ll> z1;
  8. ll w = 0;
  9. ll sol = 0;
  10. ll x;
  11. vector<bool> hp;
  12.  
  13. void solve(ll pos, ll n)
  14. {
  15.     if (pos == n)
  16.     {
  17.         if (w > x && (sol == 0 || sol < w))
  18.         {
  19.             sol = w;
  20.         }
  21.     }
  22.     for (int i = 0; i < z1.size(); i++)
  23.     {
  24.         if (hp.at(i) == false)
  25.         {
  26.             hp.at(i) = true;
  27.             w = w * 10 + z1.at(i);
  28.             solve(pos + 1, n);
  29.             hp.at(i) = false;
  30.         }
  31.     }
  32. }
  33.  
  34. int main()
  35. {
  36.  
  37.     cin >> x;
  38.  
  39.     ll ax;
  40.     ax = x;
  41.     while (ax > 0)
  42.     {
  43.         z1.push_back(ax % 10);
  44.         hp.push_back(false);
  45.         ax = ax / 10;
  46.     }
  47.  
  48.     solve(0, z1.size());
  49.  
  50.     cout << sol << endl;
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment