This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
int main(){
cin.tie(0)->sync_with_stdio(0);
int n,l,r,cur,la; cin >> n;
l = 1,r = n*2-1;
vector<int> ans;
set<int> used;
cin >> cur;
used.insert(cur);
ans.push_back(cur);
for (int i = 0;i<n-1;i++) {
la = cur; cin >> cur;
if (used.count(cur)){
if (cur == la){
while (used.count(l)) l++;
used.insert(l);
ans.push_back(l);
l++;
while (used.count(r)) r--;
used.insert(r);
ans.push_back(r);
r--;
}
else{
if (cur > la){
while (used.count(r)) r--;
used.insert(r);
ans.push_back(r);
r--;
while (used.count(r)) r--;
used.insert(r);
ans.push_back(r);
r--;
}
else{
while (used.count(l)) l++;
used.insert(l);
ans.push_back(l);
l++;
while (used.count(l)) l++;
used.insert(l);
ans.push_back(l);
l++;
}
}
}
else{
ans.push_back(cur);
used.insert(cur);
if (cur > la){
while (used.count(r)) r--;
used.insert(r);
ans.push_back(r);
r--;
}
else{
while (used.count(l)) l++;
used.insert(l);
ans.push_back(l);
l++;
}
}
}
for (auto a:ans) cout << a << ' ';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |