#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
//cout<<"intra in prima cu "<<i<<"\n";
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.end();
it--;
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.begin();
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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
18 ms |
352 KB |
Output is correct |
4 |
Correct |
2 ms |
252 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
3 ms |
376 KB |
Output is correct |
13 |
Correct |
3 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
584 KB |
Output is correct |
2 |
Correct |
6 ms |
760 KB |
Output is correct |
3 |
Correct |
11 ms |
1272 KB |
Output is correct |
4 |
Correct |
24 ms |
2168 KB |
Output is correct |
5 |
Correct |
46 ms |
4036 KB |
Output is correct |
6 |
Runtime error |
89 ms |
13948 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
7 |
Runtime error |
137 ms |
20984 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |