#include <bits/stdc++.h>
#define L 200005
using namespace std;
ifstream fin("medians.in");
ofstream fout("medians.out");
int v[L];
bool vis[L];
int main(){
int n, i, j, x, i1, i2, smaller, bigger;
fin >> n >> x;
v[1] = x;
vis[x] = true;
i1 = 1;
i2 = 2 * n - 1;
for (i = 1; i < n; i++){
while (vis[i1])
i1++;
while (vis[i2])
i2--;
fin >> x;
if (vis[x]){
smaller = 0;
for (j = 1; j < x; j++)
smaller += vis[j];
bigger = 2 * i - 2 - smaller;
if (smaller == bigger){
v[2 * i] = i1;
v[2 * i + 1] = i2;
vis[i1] = vis[i2] = true;
}
else if (smaller < bigger){
v[2 * i] = i1;
vis[i1] = true;
while (vis[i1])
i1++;
v[2 * i + 1] = i1;
vis[i1] = true;
}
else{
v[2 * i] = i2;
vis[i2] = true;
while (vis[i2])
i2++;
v[2 * i + 1] = i2;
vis[i2] = true;
}
}
else{
smaller = 0;
for (j = 1; j < x; j++)
smaller += vis[j];
bigger = 2 * i - 1 - smaller;
if (smaller > bigger){
v[2 * i] = i2;
v[2 * i + 1] = x;
vis[i2] = vis[x] = true;
}
else{
v[2 * i] = i1;
v[2 * i + 1] = x;
vis[i1] = vis[x] = true;
}
}
}
for (i = 1; i < 2 * n; i++)
fout << v[i] << " ";
fout << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
2 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
3 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
4 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
5 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
6 |
Runtime error |
1 ms |
328 KB |
Execution killed with signal 11 |
7 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
8 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
9 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
10 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
11 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
12 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
13 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
2 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
3 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
4 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
5 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
6 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
7 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |