-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreconperm.cpp
39 lines (34 loc) · 862 Bytes
/
reconperm.cpp
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
#include <bits/stdc++.h>
using namespace std;
using ll = int;
using pi = pair<ll, ll>;
using vi = vector<ll>;
using vpi = vector<pi>;
using vb = vector<bool>;
class ReconstructPermutation {
public:
vector<int> reconstruct(int n, vector<int> partial) {
set<ll> left;
for(int i = 0; i < n; i++) {
left.insert(i);
}
for(int i : partial) {
left.erase(i);
}
int j = 0;
int k = 0;
vi path(n, -1);
for (int i : left) {
cout << i << endl;
if (j == partial.size() || i < partial[j]) {
path[k++] = i;
continue;
}
while(!(i < partial[j])) {
path[k++] = partial[j++];
if (j == partial.size()) break;
}
}
return path;
}
};