BOJ 1038 감소하는 수

 
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <functional>

typedef long long int ll;
using namespace std;
#define INF 1234567890
#define N 200000

const int LIMIT = 1e+9;
int n;
ll values[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
vector<ll> vc;

ll powf(int base, int exp) {
	if (exp == 0) {
		return 1;
	}
	ll res = 1;
	while (exp) {
		if (exp & 1)
			res *= base;
		exp >>= 1;
		base *= base;
	}
	return res;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll limit = powf(2, 10);
	for (int i = 1; i < limit; i++) {
		int seed = i;
		ll res = 0;
		int cnt = 0;
		int bin_cnt = 0;
		while (seed) {
			if (seed & 1) {
				res += values[cnt] * powf(10, bin_cnt);
				bin_cnt++;
			}
			cnt++;
			seed /= 2;
		}
		vc.push_back(res);
	}
	sort(vc.begin(), vc.end());
	int n;
	cin >> n;
	if (vc.size() <= n) {
		cout << -1;
		return 0;
	}
	cout << vc[n];


	return 0;
}