Submission #267988

# Submission time Handle Problem Language Result Execution time Memory
267988 2020-08-16T07:41:52 Z stefantaga medians (balkan11_medians) C++14
100 / 100
85 ms 4216 KB
#include<bits/stdc++.h>
#define DIM 200005
using namespace std;
int n, i, p, u;
int v[DIM], ff[DIM], sol[DIM];
int main()
{
    #ifdef HOME
    ifstream cin("medians.in");
    ofstream cout("medians.out");
    #endif // HOME
    cin>> n;
    for(i = 1; i <= n; i++){
        cin>> v[i];
    }
    sol[1] = v[1];
    ff[ v[1] ] = 1;
    p = 1;
    u = 2 * n - 1;
    for(i = 2; i <= n; i++){
        while(ff[p] == 1){
            p++;
        }
        while(ff[u] == 1){
            u--;
        }
        if(v[i] == v[i - 1]){
            sol[2 * i - 2] = p;
            sol[2 * i - 1] = u;
            ff[p] = ff[u] = 1;
        }
        else{
            if(ff[ v[i] ] == 0){
                sol[2 * i - 2] = v[i];
                ff[ v[i] ] = 1;
                if(v[i] > v[i - 1]){
                    sol[2 * i - 1] = u;
                    ff[u] = 1;
                }
                else{
                    sol[2 * i - 1] = p;
                    ff[p] = 1;
                }
            }
            else{
                if(v[i] > v[i - 1]){
                    sol[2 * i - 2] = u;
                    ff[u] = 1;
                    while(ff[u] == 1){
                        u--;
                    }
                    sol[2 * i - 1] = u;
                    ff[u] = 1;
                }
                else{
                    sol[2 * i - 2] = p;
                    ff[p] = 1;
                    while(ff[p] == 1){
                        p++;
                    }
                    sol[2 * i - 1] = p;
                    ff[p] = 1;
                }
            }
        }
    }
    for(i = 1; i <= 2 * n - 1; i++){
        cout<< sol[i] <<" ";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 6 ms 640 KB Output is correct
4 Correct 13 ms 896 KB Output is correct
5 Correct 26 ms 1580 KB Output is correct
6 Correct 58 ms 2808 KB Output is correct
7 Correct 85 ms 4216 KB Output is correct