#include <iostream>
#include <set>
using namespace std;
set<int> se;
int a[100005];
int b[200005];
int main()
{
int n,cnt=1;
cin>>n;
for(int i=1;i<=n;i++){
cin>>b[i];
}
for(int i=1;i<=2*n-1;i++){
se.insert(i);
}
a[1]=b[1];
se.erase(a[1]);
set<int>::iterator it;
for(int i=2;i<=n;i++){
if(b[i]==b[i-1]){
///trebuie bagate doua elemente, unu mai mare ca b[i],unu mai mic ca b[i]
///le bagam pe cel mai mare si cel mai mic element nefolosit
it=se.begin();
a[++cnt]=*it;
se.erase(it);
it=se.end();
it--;
a[++cnt]=*it;
se.erase(it);
}
else
if(b[i]>b[i-1]){
if(se.count(b[i])==0){
it=se.begin();
a[++cnt]=*it;
se.erase(it);
it=se.end();
it--;
a[++cnt]=*it;
se.erase(it);
///exista deja mijlocul
}
else{
se.erase(b[i]);
a[++cnt]=b[i];
it=se.end();
it--;
a[++cnt]=*it;
se.erase(it);
}
}
else{
if(se.count(b[i])==0){
it=se.begin();
a[++cnt]=*it;
se.erase(it);
it=se.end();
it--;
a[++cnt]=*it;
se.erase(it);
}
else{
se.erase(b[i]);
a[++cnt]=b[i];
it=se.begin();
a[++cnt]=*it;
se.erase(it);
}
}
}
for(int i=1;i<=2*n-1;i++)
cout<<a[i]<<" ";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
5 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
8 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
9 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
10 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
11 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
12 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
13 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
508 KB |
Output isn't correct |
2 |
Incorrect |
7 ms |
760 KB |
Output isn't correct |
3 |
Incorrect |
11 ms |
1272 KB |
Output isn't correct |
4 |
Incorrect |
23 ms |
2168 KB |
Output isn't correct |
5 |
Incorrect |
47 ms |
4088 KB |
Output isn't correct |
6 |
Runtime error |
89 ms |
13936 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
7 |
Runtime error |
138 ms |
20984 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |