Submission #958383

# Submission time Handle Problem Language Result Execution time Memory
958383 2024-04-05T16:57:06 Z AndreiBOTO medians (balkan11_medians) C++14
100 / 100
19 ms 3672 KB
#include <bits/stdc++.h>

#pragma optimize GCC ("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

///#include <tryhardmode>
///#include <GODMODE::ON>

using namespace std;

const int NMAX=2e5+5;

bool viz[NMAX];
int a[NMAX];
int b[NMAX];

int st,dr;

void go_left()
{
    while(viz[st])
        st++;
    return ;
}

void go_right()
{
    while(viz[dr])
        dr--;
    return ;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n,i;
    cin>>n;
    st=1,dr=2*n-1;
    for(i=1;i<=n;i++)
        cin>>b[i];
    a[1]=b[1];
    viz[b[1]]=true;
    for(i=2;i<=n;i++)
    {
        if(b[i]==b[i-1])
        {
            go_left();
            a[2*(i-1)]=st;
            viz[st]=true;
            go_right();
            a[2*(i-1)+1]=dr;
            viz[dr]=true;
        }
        else if(b[i]>b[i-1])
        {
            if(!viz[b[i]])
            {
                a[2*(i-1)]=b[i];
                viz[b[i]]=true;
                go_right();
                a[2*(i-1)+1]=dr;
                viz[dr]=true;
            }
            else
            {
                go_right();
                a[2*(i-1)]=dr;
                viz[dr]=true;
                go_right();
                a[2*(i-1)+1]=dr;
                viz[dr]=true;
            }
        }
        else if(b[i]<b[i-1])
        {
            if(!viz[b[i]])
            {
                a[2*(i-1)]=b[i];
                viz[b[i]]=true;
                go_left();
                a[2*(i-1)+1]=st;
                viz[st]=true;
            }
            else
            {
                go_left();
                a[2*(i-1)]=st;
                viz[st]=true;
                go_left();
                a[2*(i-1)+1]=st;
                viz[st]=true;
            }
        }
    }
    for(i=1;i<=2*n-1;i++)
        cout<<a[i]<<" ";
    return 0;
}

Compilation message

medians.cpp:3: warning: ignoring '#pragma optimize GCC' [-Wunknown-pragmas]
    3 | #pragma optimize GCC ("Ofast")
      |
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 3 ms 860 KB Output is correct
5 Correct 6 ms 1624 KB Output is correct
6 Correct 12 ms 2448 KB Output is correct
7 Correct 19 ms 3672 KB Output is correct