Submission #646138

# Submission time Handle Problem Language Result Execution time Memory
646138 2022-09-28T18:43:49 Z Matteo_Verz medians (balkan11_medians) C++17
100 / 100
25 ms 2888 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 vector <bool> &visited) {
    while (visited[last] == true)
        last += coef;
}

void insertValue(int value, int &l, int &r, vector <int> &v, vector <bool> &visited) {
    v.push_back(value);
    visited[value] = true;
    nextValue(l, 1, visited);
    nextValue(r, -1, visited);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector <int> a, b(n);
    vector <bool> visited(2 * n);

    cin >> b[0];
    a.push_back(b[0]);
    visited[b[0]] = true;

    int l = 1, r = 2 * n - 1;
    for (int i = 1; i < n; i++) {
        cin >> b[i];
        nextValue(l, 1, visited);
        nextValue(r, -1, visited);

        if (b[i] == b[i - 1]) {
            insertValue(l, l, r, a, visited);
            insertValue(r, l, r, a, visited);
        } else if (b[i] > b[i - 1]) {
            if (visited[b[i]] == false) {
                insertValue(b[i], l, r, a, visited);
                insertValue(r, l, r, a, visited);
            } else {
                insertValue(r, l, r, a, visited);
                insertValue(r, l, r, a, visited);
            }
        } else {
            if (visited[b[i]] == false) {
                insertValue(b[i], l, r, a, visited);
                insertValue(l, l, r, a, visited);
            } else {
                insertValue(l, l, r, a, visited);
                insertValue(l, l, r, a, visited);
            }
        }
    }

    for (auto it : a)
        cout << it << ' ';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 6 ms 852 KB Output is correct
5 Correct 8 ms 1112 KB Output is correct
6 Correct 16 ms 1924 KB Output is correct
7 Correct 25 ms 2888 KB Output is correct