Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using ll = long long;
- using ld = long double;
- using namespace std;
- vector<ll> z1;
- ll w = 0;
- ll sol = 0;
- ll x;
- vector<bool> hp;
- void solve(ll pos, ll n)
- {
- if (pos == n)
- {
- if (w > x && (sol == 0 || sol > w))
- {
- sol = w;
- }
- w = 0;
- }
- for (int i = 0; i < z1.size(); i++)
- {
- if (hp.at(i) == false)
- {
- hp.at(i) = true;
- w = w * 10 + z1.at(i);
- solve(pos + 1, n);
- hp.at(i) = false;
- }
- }
- }
- int main()
- {
- cin >> x;
- ll ax;
- ax = x;
- while (ax > 0)
- {
- z1.push_back(ax % 10);
- hp.push_back(false);
- ax = ax / 10;
- }
- solve(0, z1.size());
- cout << sol << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment