#include <bits/stdc++.h>
using namespace std;
const int maxn = 100100;
int a[2*maxn], b[maxn], n;
int minvalue, maxvalue;
bool visited[2*maxn];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n;
for(int i=1;i<=n;i++) {
cin>>b[i];
}
minvalue = 1;
maxvalue = 2*n-1;
visited[b[1]]=true;
a[1] = b[1];
while(visited[minvalue]) minvalue++;
while(visited[maxvalue]) maxvalue--;
for(int i=2;i<=n;i++) {
if(b[i] == b[i-1]) {
a[2*(i-1)] = minvalue;
visited[minvalue] = true;
while(visited[minvalue]) minvalue++;
a[2*(i-1)+1] = maxvalue;
visited[maxvalue] = true;
while(visited[maxvalue]) maxvalue--;
}
else if(b[i] < b[i-1]) {
if(visited[b[i]]) {
a[2*(i-1)] = minvalue;
visited[minvalue] = true;
while(visited[minvalue]) minvalue++;
a[2*(i-1)+1] = minvalue;
visited[minvalue] = true;
while(visited[minvalue]) minvalue++;
}
else {
a[2*(i-1)] = b[i];
visited[b[i]] = true;
while(visited[minvalue]) minvalue++;
a[2*(i-1)+1] = minvalue;
visited[minvalue] = true;
while(visited[minvalue]) minvalue++;
}
}
else if(b[i] > b[i-1]) {
if(visited[b[i]]) {
a[2*(i-1)] = maxvalue;
visited[maxvalue] = true;
while(visited[maxvalue]) maxvalue--;
a[2*(i-1)+1] = maxvalue;
visited[maxvalue] = true;
while(visited[maxvalue]) maxvalue--;
}
else {
a[2*(i-1)] = b[i];
visited[b[i]] = true;
while(visited[maxvalue]) maxvalue--;
a[2*(i-1)+1] = maxvalue;
visited[maxvalue] = true;
while(visited[maxvalue]) maxvalue--;
}
}
}
for(int i=1;i<=2*n-1;i++) {
cout<<a[i]<<" ";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
496 KB |
Output is correct |
3 |
Correct |
2 ms |
496 KB |
Output is correct |
4 |
Correct |
2 ms |
496 KB |
Output is correct |
5 |
Correct |
2 ms |
564 KB |
Output is correct |
6 |
Correct |
2 ms |
612 KB |
Output is correct |
7 |
Correct |
2 ms |
644 KB |
Output is correct |
8 |
Correct |
2 ms |
648 KB |
Output is correct |
9 |
Correct |
3 ms |
648 KB |
Output is correct |
10 |
Correct |
3 ms |
656 KB |
Output is correct |
11 |
Correct |
2 ms |
788 KB |
Output is correct |
12 |
Correct |
2 ms |
788 KB |
Output is correct |
13 |
Correct |
3 ms |
788 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
788 KB |
Not a permutation |
2 |
Correct |
5 ms |
860 KB |
Output is correct |
3 |
Correct |
5 ms |
1008 KB |
Output is correct |
4 |
Incorrect |
8 ms |
1320 KB |
Not a permutation |
5 |
Correct |
12 ms |
1664 KB |
Output is correct |
6 |
Incorrect |
26 ms |
2576 KB |
Not a permutation |
7 |
Correct |
34 ms |
3472 KB |
Output is correct |