이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int n;
cin>>n;
int b[n];
for(int i = 0; i < n; i++)cin>>b[i];
vector<int>ans;
int mn = 1, mx = 2 * n - 1;
bool used[2 * n]={0};
used[b[0]] = 1;
ans.push_back(b[0]);
auto addMax = [&](){
while(used[mx])mx--;
ans.push_back(mx);
used[mx]=1;
};
auto addMin = [&](){
while(used[mn])mn++;
ans.push_back(mn);
used[mn]=1;
};
for(int i = 1; i < n; i++){
if(b[i] == b[i - 1]){
addMax();
addMin();
}
else if(b[i] > b[i - 1]){
addMax();
if(!used[b[i]]){
ans.push_back(b[i]);
used[b[i]] = 1;
}
else addMax();
}
else{
addMin();
if(!used[b[i]]){
ans.push_back(b[i]);
used[b[i]] = 1;
}
else addMin();
}
}
for(int i : ans)cout<<i<<' ';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |