Submission #2384454


Source Code Expand

// Many Medians

#define NODEBUG

#include<utility>
#include<type_traits>
#include<iostream>
#include<vector>
#include<algorithm>
#include<iterator>
#include<cassert>

using namespace std;

using X_type = int32_t;

template<typename T, typename Iter>
pair<T,T> sub(Iter first,Iter last, size_t n)
{
        static_assert(is_base_of<random_access_iterator_tag, typename iterator_traits<Iter>::iterator_category>::value,
                        "ランダムアクセス反復子じゃない");

        vector<T> tmp(first,last);
        assert(n==tmp.size());
        assert(n%2==0);

        typename vector<T>::iterator mid;

        mid = tmp.begin()+(n/2)-1;
        nth_element(tmp.begin(), mid, tmp.end());
        T min_cand = *mid;

        mid = tmp.begin()+(n/2);
        nth_element(tmp.begin(), mid, tmp.end());
        T max_cand = *mid;

        return {min_cand,max_cand};
}

int main(){
        size_t N;
        cin >> N;
        assert(N%2==0);

        vector<X_type> X;
        X.reserve(N);
        copy_n(istream_iterator<X_type>{cin}, N, back_inserter(X));

        auto p = sub<X_type>(X.begin(), X.end(), N);
        transform(X.begin(), X.end(), ostream_iterator<X_type>{cout,"\n"},
                        [p](X_type x){ return x<p.second ? p.second : p.first; });

        cout.flush();
        return 0;
}

Submission Info

Submission Time
Task C - Many Medians
User donald9016
Language C++14 (GCC 5.4.1)
Score 300
Code Size 1390 Byte
Status AC
Exec Time 101 ms
Memory 2940 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 18
Set Name Test Cases
Sample sample1.txt, sample2.txt, sample3.txt
All sample1.txt, sample2.txt, sample3.txt, 1.txt, 10.txt, 11.txt, 12.txt, 2.txt, 3.txt, 4.txt, 5.txt, 6.txt, 7.txt, 8.txt, 9.txt, sample1.txt, sample2.txt, sample3.txt
Case Name Status Exec Time Memory
1.txt AC 1 ms 256 KB
10.txt AC 95 ms 2848 KB
11.txt AC 93 ms 2556 KB
12.txt AC 72 ms 2128 KB
2.txt AC 50 ms 1540 KB
3.txt AC 97 ms 2828 KB
4.txt AC 94 ms 2852 KB
5.txt AC 99 ms 2940 KB
6.txt AC 95 ms 2848 KB
7.txt AC 75 ms 2232 KB
8.txt AC 94 ms 2848 KB
9.txt AC 101 ms 2928 KB
sample1.txt AC 1 ms 256 KB
sample2.txt AC 1 ms 256 KB
sample3.txt AC 1 ms 256 KB