답안 #376981

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
376981 2021-03-12T14:04:39 Z iliccmarko 중앙값 배열 (balkan11_medians) C++14
5 / 100
35 ms 4328 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define INF 1000000000
#define LINF 1000000000000000LL
#define pb push_back
#define all(x) x.begin(), x.end()
#define len(s) (int)s.size()
#define test_case { int t; cin>>t; while(t--)solve(); }
#define input(n, v) {for(int i = 0;i<n;i++) cin>>v[i];}
#define output(n, v) {for(int i = 0;i<n;i++) cout<<v[i]<<" "; cout<<endl;}
#define single_case solve();
#define line cout<<"------------"<<endl;
#define ios { ios_base::sync_with_stdio(false); cin.tie(NULL); }
const int N = 2e5 + 50;
vector<int> a;
int b[N];
int n;
int c[N];
int l, r;

int main()
{
    ios
    cin>>n;
    for(int i = 1;i<=n;i++) cin>>b[i];
    a.pb(b[1]);
    c[b[1]]++;
    int l = 1;
    int r = 2*n-1;
    for(int i = 2;i<=n;i++)
    {
        while(c[l])l++;
        while(c[r])r--;
        int levo = l-1;
        int desno = 2*n-1-r;
        if(l>b[i]) levo--;
        if(r<b[i]) desno--;
        if(!c[b[i]])
        {
            c[b[i]]++;
            while(c[l])l++;
        while(c[r])r--;
        a.pb(b[i]);
        if(levo<desno)
        {
            a.pb(l);
            c[l]++;
        }
        else
        {
            a.pb(r);
            c[r]++;
        }
        }
        else
        {
            if(levo<desno)
            {
                while(c[l])l++;
                c[l]++;
                a.pb(l);
                while(c[l])l++;
                c[l]++;
                a.pb(l);
            }
            else if(desno>levo)
            {
                while(c[r])r--;
                c[r]++;
                a.pb(r);
                while(c[r])r--;
                c[r]++;
                a.pb(r);
            }
            else
            {
                while(c[r])r--;
                a.pb(r);
                c[r]++;
                while(c[l])l++;
                a.pb(l);
                c[l]++;
            }
        }
    }

    for(int x : a) cout<<x<<" ";



    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Incorrect 1 ms 364 KB Output isn't correct
5 Incorrect 1 ms 364 KB Output isn't correct
6 Correct 1 ms 364 KB Output is correct
7 Incorrect 1 ms 364 KB Output isn't correct
8 Incorrect 1 ms 364 KB Output isn't correct
9 Incorrect 1 ms 364 KB Output isn't correct
10 Incorrect 1 ms 364 KB Output isn't correct
11 Incorrect 1 ms 364 KB Output isn't correct
12 Incorrect 1 ms 364 KB Output isn't correct
13 Incorrect 1 ms 384 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 492 KB Output isn't correct
2 Incorrect 3 ms 492 KB Output isn't correct
3 Incorrect 3 ms 748 KB Output isn't correct
4 Incorrect 6 ms 1132 KB Output isn't correct
5 Incorrect 10 ms 1648 KB Output isn't correct
6 Incorrect 20 ms 2924 KB Output isn't correct
7 Incorrect 35 ms 4328 KB Output isn't correct