#include<iostream>
#include<vector>
using namespace std;
bool visi[200002];
int A[200002];
int B[100001];
int main()
{
int n;
cin>>n;
int maxi=2*n;
int mini=0;
visi[2*n]=true;
visi[0]=true;
for(int i=1;i<=n;i++)
{
int a;
cin>>a;
B[i]=a;
}
visi[B[1]]=true;
A[1]=B[1];
for(int i=2;i<=n;i++)
{
if(B[i]==B[i-1])
{
while(visi[mini])
mini++;
while(visi[maxi])
maxi--;
visi[maxi]=true;
visi[mini]=true;
A[2*i-2]=mini;
A[2*i-1]=maxi;
}
else if(B[i]>B[i-1])
{
if(!visi[B[i]])
{
A[2*i-2]=B[i];
while(visi[maxi])
maxi--;
visi[maxi]=true;
A[2*i-1]=maxi;
}
else
{
while(visi[maxi])
maxi--;
visi[maxi]=true;
A[2*i-2]=maxi;
while(visi[maxi])
maxi--;
visi[maxi]=true;
A[2*i-1]=maxi;
}
}
else if(B[i]<B[i-1])
{
if(!visi[B[i]])
{
A[2*i-2]=B[i];
while(visi[mini])
mini++;
visi[mini]=true;
A[2*i-1]=mini;
}
else
{
while(visi[mini])
mini++;
visi[mini]=true;
A[2*i-2]=mini;
while(visi[mini])
mini++;
visi[mini]=true;
A[2*i-1]=mini;
}
}
}
for(int i=1;i<=2*n-1;i++)
{
if(i!=1)
cout<<" ";
cout<<A[i];
}
cout<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
3388 KB |
Output is correct |
2 |
Incorrect |
0 ms |
3388 KB |
Not a permutation |
3 |
Incorrect |
0 ms |
3388 KB |
Not a permutation |
4 |
Incorrect |
0 ms |
3388 KB |
Not a permutation |
5 |
Incorrect |
0 ms |
3388 KB |
Not a permutation |
6 |
Correct |
0 ms |
3388 KB |
Output is correct |
7 |
Incorrect |
0 ms |
3388 KB |
Not a permutation |
8 |
Incorrect |
0 ms |
3388 KB |
Not a permutation |
9 |
Incorrect |
0 ms |
3388 KB |
Not a permutation |
10 |
Incorrect |
0 ms |
3388 KB |
Not a permutation |
11 |
Incorrect |
0 ms |
3388 KB |
Not a permutation |
12 |
Incorrect |
0 ms |
3388 KB |
Not a permutation |
13 |
Incorrect |
0 ms |
3388 KB |
Not a permutation |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
3388 KB |
Not a permutation |
2 |
Incorrect |
0 ms |
3388 KB |
Not a permutation |
3 |
Incorrect |
3 ms |
3388 KB |
Not a permutation |
4 |
Incorrect |
9 ms |
3388 KB |
Not a permutation |
5 |
Incorrect |
16 ms |
3388 KB |
Not a permutation |
6 |
Incorrect |
36 ms |
3388 KB |
Not a permutation |
7 |
Incorrect |
49 ms |
3388 KB |
Not a permutation |