#include <bits/stdc++.h>
using namespace std;
const int MAXN=100000;
int vmin, vmax;
bool used[2*MAXN]={false};
void updatevmin()
{
while (used[vmin])
vmin=vmin+1;
return;
}
void updatevmax()
{
while (used[vmax])
vmax=vmax-1;
return;
}
int main()
{
int n, i;
cin >> n;
int a[2*n-1], b[n];
for (i=0; i<n; i++)
cin >> b[i];
vmin=1;
vmax=2*n-1;
a[0]=b[0];
used[b[0]]=true;
for (i=1; i<n; i++)
{
if (b[i]==b[i-1])
{
updatevmin();
a[2*i-1]=vmin;
used[vmin]=true;
updatevmax();
a[2*i]=vmax;
used[vmax]=true;
}
if (b[i]>b[i-1])
{
if (used[b[i]])
{
updatevmax();
a[2*i-1]=vmax;
used[vmax]=true;
updatevmax();
a[2*i]=vmax;
used[vmax]=true;
}
else
{
a[2*i-1]=b[i];
used[b[i]]=true;
updatevmax();
a[2*i]=vmax;
used[vmax]=true;
}
}
if (b[i]<b[i-1])
{
if (used[b[i]])
{
updatevmin();
a[2*i-1]=vmin;
used[vmin]=true;
updatevmin();
a[2*i]=vmin;
used[vmin]=true;
}
else
{
a[2*i-1]=b[i];
used[b[i]]=true;
updatevmin();
a[2*i]=vmin;
used[vmin]=true;
}
}
}
for (i=0; i<2*n-1; i++)
cout << a[i] << " ";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
348 KB |
Output is correct |
3 |
Correct |
3 ms |
600 KB |
Output is correct |
4 |
Correct |
6 ms |
600 KB |
Output is correct |
5 |
Correct |
11 ms |
1116 KB |
Output is correct |
6 |
Correct |
27 ms |
1872 KB |
Output is correct |
7 |
Correct |
34 ms |
2900 KB |
Output is correct |