-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1174.cpp
More file actions
42 lines (32 loc) · 758 Bytes
/
Copy path1174.cpp
File metadata and controls
42 lines (32 loc) · 758 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
int N;
string num = "0123456789";
vector<ll> asc;
void backtracking(int idx, string temp){
if(!temp.empty()){
string _temp = temp;
reverse(_temp.begin(),_temp.end());
asc.push_back(stoll(_temp));
}
for(int i=idx+1; i<10; i++){
temp += num[i];
backtracking(i, temp);
temp.pop_back();
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>N;
for(int i=0; i<10; i++){
string temp = "";
backtracking(i,temp+=num[i]);
}
sort(asc.begin(), asc.end());
if(N>asc.size()) cout<<-1;
else cout<<asc[N-1];
}