답안 #145482

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
145482 2019-08-20T08:19:45 Z MKopchev 중앙값 배열 (balkan11_medians) C++14
10 / 100
131 ms 12808 KB
#include<bits/stdc++.h>
using namespace std;
const int nmax=2e5+42;
int n,inp[nmax];
int output[nmax];

set<int> active;

map<int,int> seen;
int get_front()
{
    set<int>::iterator it=active.begin();
    int num=*it;
    active.erase(it);
    return num;
}
int get_back()
{
    set<int>::iterator it=active.end();
    it--;
    int num=*it;
    active.erase(it);
    return num;
}
int main()
{
    scanf("%i",&n);
    for(int i=1;i<=n;i++)
        scanf("%i",&inp[i]);

    for(int i=1;i<=2*n-1;i++)
        active.insert(i);

    output[1]=inp[1];

    for(int i=1;i<n;i++)
    {
        seen[inp[i]]++;
        active.erase(inp[i]);
    }

    for(int i=n-1;i>=1;i--)
    {
        if(inp[i]<inp[i+1])
        {
            output[2*i+1]=get_back();
            output[2*i]=get_back();
        }
        else if(inp[i]>inp[i+1])
        {
            output[2*i+1]=get_front();
            output[2*i]=get_front();
        }
        else
        {
            output[2*i+1]=get_back();
            output[2*i]=get_front();
        }
        seen[inp[i]]--;
        if(seen[inp[i]]==0)
            active.insert(inp[i]);
    }
    for(int i=1;i<=2*n-1;i++)
        printf("%i ",output[i]);
    return 0;
}

Compilation message

medians.cpp: In function 'int main()':
medians.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i",&n);
     ~~~~~^~~~~~~~~
medians.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%i",&inp[i]);
         ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Correct 2 ms 248 KB Output is correct
4 Incorrect 2 ms 376 KB Output isn't correct
5 Incorrect 2 ms 504 KB Output isn't correct
6 Correct 2 ms 256 KB Output is correct
7 Incorrect 2 ms 376 KB Output isn't correct
8 Incorrect 2 ms 376 KB Output isn't correct
9 Incorrect 2 ms 376 KB Output isn't correct
10 Incorrect 2 ms 376 KB Output isn't correct
11 Incorrect 2 ms 376 KB Output isn't correct
12 Incorrect 3 ms 376 KB Output isn't correct
13 Incorrect 3 ms 504 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 632 KB Output isn't correct
2 Incorrect 6 ms 760 KB Output isn't correct
3 Incorrect 10 ms 1272 KB Output isn't correct
4 Incorrect 20 ms 2296 KB Output isn't correct
5 Incorrect 38 ms 4344 KB Output isn't correct
6 Incorrect 84 ms 8332 KB Output isn't correct
7 Incorrect 131 ms 12808 KB Output isn't correct