#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
using namespace std;
ll n,i,a[202020],b[202020],sud[202020],jaw[202020],j;
int main()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
cin>>n;
for(i=1;i<=n;i++)cin>>a[i];
for(i=1;i<n;i++)b[a[i]]++;
jaw[1]=a[1];
for(i=n-1;i>=1;i--)
{
if(a[i]>a[i+1])
{
for(j=a[i];j>=1;j--)
if(b[j]==0&&sud[j]==0)
{
b[j]=1;
sud[j]=1;
jaw[i*2]=j;
break;
}
for(j=a[i];j>=1;j--)
if(b[j]==0&&sud[j]==0)
{
b[j]=1;
sud[j]=1;
jaw[i*2+1]=j;
break;
}
}
else
if(a[i]<a[i+1])
{
for(j=a[i];j<=n*2-1;j++)
if(b[j]==0&&sud[j]==0)
{
b[j]=1;
sud[j]=1;
jaw[i*2]=j;
break;
}
for(j=a[i];j<=n*2-1;j++)
if(b[j]==0&&sud[j]==0)
{
b[j]=1;
sud[j]=1;
jaw[i*2+1]=j;
break;
}
}
else
{
for(j=a[i];j>=1;j--)
if(b[j]==0&&sud[j]==0)
{
b[j]=1;
sud[j]=1;
jaw[i*2]=j;
break;
}
for(j=a[i];j<=n*2-1;j++)
if(b[j]==0&&sud[j]==0)
{
b[j]=1;
sud[j]=1;
jaw[i*2+1]=j;
break;
}
}
b[a[i]]--;
}
for(i=1;i<=(n*2-1);i++)
if(i<(n*2-1))
cout<<jaw[i]<<" ";
else
cout<<jaw[i]<<"\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
512 KB |
Output is correct |
2 |
Correct |
16 ms |
612 KB |
Output is correct |
3 |
Correct |
59 ms |
888 KB |
Output is correct |
4 |
Correct |
212 ms |
1536 KB |
Output is correct |
5 |
Execution timed out |
828 ms |
2872 KB |
Time limit exceeded |
6 |
Execution timed out |
1070 ms |
3256 KB |
Time limit exceeded |
7 |
Execution timed out |
1068 ms |
3672 KB |
Time limit exceeded |