답안 #199258

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
199258 2020-01-30T18:12:12 Z Andrei_Cotor 중앙값 배열 (balkan11_medians) C++14
100 / 100
36 ms 3576 KB
#include<iostream>

using namespace std;

int st,dr,Viz[200005],Rez[200005],A[100005];

void addmn(int poz)
{
    while(Viz[st])
        st++;

    Rez[poz]=st;
    Viz[st]=1;
}

void addmx(int poz)
{
    while(Viz[dr])
        dr--;

    Rez[poz]=dr;
    Viz[dr]=1;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin>>n;
    for(int i=1; i<=n; i++)
        cin>>A[i];

    Rez[1]=A[1];
    Viz[A[1]]=1;
    st=1;
    dr=2*n-1;
    for(int i=2; i<=n; i++)
    {
        if(A[i]==A[i-1])
        {
            addmn(2*i-2);
            addmx(2*i-1);
        }
        else if(A[i]>A[i-1])
        {
            if(!Viz[A[i]])
            {
                Rez[2*i-2]=A[i];
                Viz[A[i]]=1;
                addmx(2*i-1);
            }
            else
            {
                addmx(2*i-2);
                addmx(2*i-1);
            }
        }
        else
        {
            if(!Viz[A[i]])
            {
                Rez[2*i-2]=A[i];
                Viz[A[i]]=1;
                addmn(2*i-1);
            }
            else
            {
                addmn(2*i-2);
                addmn(2*i-1);
            }
        }
    }

    for(int i=1; i<=2*n-1; i++)
        cout<<Rez[i]<<" ";
    cout<<"\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 380 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 380 KB Output is correct
2 Correct 6 ms 504 KB Output is correct
3 Correct 8 ms 632 KB Output is correct
4 Correct 10 ms 892 KB Output is correct
5 Correct 15 ms 1396 KB Output is correct
6 Correct 24 ms 2424 KB Output is correct
7 Correct 36 ms 3576 KB Output is correct