답안 #646132

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
646132 2022-09-28T18:25:54 Z Matteo_Verz 중앙값 배열 (balkan11_medians) C++17
10 / 100
109 ms 12004 KB
#include <bits/stdc++.h>
#ifdef BLAT
   #include "debug/debug.hpp"
#else
   #define debug(x...)
#endif

using namespace std;

void nextValue(int &last, int coef, const set <int> &myset) {
    while (myset.find(last) == myset.end())
        last += coef;
}

void insertValue(int value, vector <int> &v, set <int> &myset) {
    v.push_back(value);
    myset.erase(value);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    vector <int> a, b;
    set <int> myset;
    cin >> n;
    b.resize(n);

    cin >> b[0];
    a.push_back(b[0]);
    for (int i = 1; i < 2 * n; i++)
        if (i != b[0])
            myset.insert(i);

    int l = *myset.begin(); 
    int r = *myset.rbegin();

    for (int i = 1; i < n; i++) {
        cin >> b[i];
        nextValue(l, 1, myset);
        nextValue(r, -1, myset);
        if (b[i] == b[i - 1]) {
            insertValue(l, a, myset);
            insertValue(r, a, myset);
        } else {
            if (myset.find(b[i]) != myset.end()) {
                a.push_back(b[i]);
                myset.erase(b[i]);

                if (l - 1 > 2 * n - 1 - r) {
                    nextValue(r, -1, myset);
                    insertValue(r, a, myset);
                } else {
                    nextValue(l, 1, myset);
                    insertValue(l, a, myset);
                }
            } else for (int j = 0; j < 2; j++) {
                    if (l - 1 > 2 * n - 1 - r) {
                        nextValue(r, -1, myset);
                        insertValue(r, a, myset);
                    } else {
                        nextValue(l, 1, myset);
                        insertValue(l, a, myset);
                    }
                }
        }
    }

    for (auto it : a)
        cout << it << ' ';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Incorrect 1 ms 324 KB Output isn't correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Incorrect 0 ms 212 KB Output isn't correct
6 Correct 0 ms 320 KB Output is correct
7 Incorrect 1 ms 212 KB Output isn't correct
8 Incorrect 1 ms 212 KB Output isn't correct
9 Incorrect 1 ms 316 KB Output isn't correct
10 Incorrect 1 ms 340 KB Output isn't correct
11 Incorrect 1 ms 324 KB Output isn't correct
12 Incorrect 1 ms 340 KB Output isn't correct
13 Incorrect 1 ms 340 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 468 KB Output isn't correct
2 Incorrect 4 ms 724 KB Output isn't correct
3 Incorrect 7 ms 1228 KB Output isn't correct
4 Incorrect 14 ms 2132 KB Output isn't correct
5 Incorrect 32 ms 3876 KB Output isn't correct
6 Incorrect 64 ms 7628 KB Output isn't correct
7 Incorrect 109 ms 12004 KB Output isn't correct