-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1038.cpp
More file actions
55 lines (50 loc) · 872 Bytes
/
Copy path1038.cpp
File metadata and controls
55 lines (50 loc) · 872 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
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <vector>
#include <iostream>
#include <queue>
using namespace std;
long long mx = 9876543210;
long long ans = -1;
int cnt = 0;
int n;
priority_queue<long long,vector<long long>, greater<long long> >pq;
int bfs()
{
while(!pq.empty())
{
long long tmp = pq.top();
pq.pop();
cnt++;
if(cnt==n)
{
ans = tmp;
return 0;
}
int k = tmp%10;
tmp = tmp * 10;
for (int i = 0; i <k ; ++i)
{
pq.push(tmp+i);
}
}
return 0;
}
int main(int argc, char** argv)
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long i = 1;
cin>>n;
while(i<10)
{
pq.push(i);
i++;
}
if(n==0) cout<<0<<"\n";
else
{
bfs();
cout<<ans<<"\n";
}
return 0;
}