T3000

Untitled

Jun 1st, 2022
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 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.         w = 0;
  22.     }
  23.     for (int i = 0; i < z1.size(); i++)
  24.     {
  25.         if (hp.at(i) == false)
  26.         {
  27.             hp.at(i) = true;
  28.             w = w * 10 + z1.at(i);
  29.             solve(pos + 1, n);
  30.             hp.at(i) = false;
  31.         }
  32.     }
  33. }
  34.  
  35. int main()
  36. {
  37.  
  38.     cin >> x;
  39.  
  40.     ll ax;
  41.     ax = x;
  42.     while (ax > 0)
  43.     {
  44.         z1.push_back(ax % 10);
  45.         hp.push_back(false);
  46.         ax = ax / 10;
  47.     }
  48.  
  49.     solve(0, z1.size());
  50.  
  51.     cout << sol << endl;
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment