Submission #163072

# Submission time Handle Problem Language Result Execution time Memory
163072 2019-11-11T10:22:36 Z Nashik medians (balkan11_medians) C++14
100 / 100
158 ms 12204 KB
#include <iostream>
#include <set>
using namespace std;
set<int> se;
int a[200005];
int b[100005];
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 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 1 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 504 KB Output is correct
2 Correct 7 ms 760 KB Output is correct
3 Correct 12 ms 1272 KB Output is correct
4 Correct 23 ms 2168 KB Output is correct
5 Correct 48 ms 4092 KB Output is correct
6 Correct 97 ms 7900 KB Output is correct
7 Correct 158 ms 12204 KB Output is correct