이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <set>
#define ll long long
#define MAXN 200010
#define pb push_back
#define pii pair<int, int>
#define xx first
#define yy second
using namespace std;
int n, b[MAXN], a[MAXN];
bool bio[MAXN];
int main() {
cin>>n;
for (int i=1; i<=n; i++) cin>>b[i];
a[1]=b[1];
bio[a[1]]=true;
set<int> s;
for (int i=1; i<=2*n-1; i++) if (i!=a[1]) s.insert(i);
for (int i=2; i<=n; i++)
{
if (b[i]>b[i-1])
{
if (!bio[b[i]])
{
a[2*i-2]=b[i];
bio[b[i]]=true;
s.erase(b[i]);
}
else
{
int x=*(s.rbegin());
a[2*i-2]=x;
bio[x]=true;
s.erase(x);
}
int x=*(s.rbegin());
a[2*i-1]=x;
bio[x]=true;
s.erase(x);
}
else if (b[i]<b[i-1])
{
if (!bio[b[i]])
{
a[2*i-2]=b[i];
bio[b[i]]=true;
s.erase(b[i]);
}
else
{
int x=*(s.begin());
a[2*i-2]=x;
bio[x]=true;
s.erase(x);
}
int x=*(s.begin());
a[2*i-1]=x;
bio[x]=true;
s.erase(x);
}
else
{
int x=*(s.begin());
a[2*i-2]=x;
bio[x]=true;
s.erase(x);
x=*(s.rbegin());
a[2*i-1]=x;
bio[x]=true;
s.erase(x);
}
}
for (int i=1; i<=2*n-1; i++) cout<<a[i]<<" ";
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |