Submission #866078

# Submission time Handle Problem Language Result Execution time Memory
866078 2023-10-25T11:33:33 Z Blagoj medians (balkan11_medians) C++17
100 / 100
73 ms 11344 KB
#include <bits/stdc++.h>

using namespace std;

#define endl '\n'
#define ll long long
#define all(x) x.begin(), x.end()

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    set<int> notUsed;
    for (int i = 1; i <= n * 2 - 1; i++) notUsed.insert(i);
    vector<int> ans, a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    ans.push_back(a[0]);
    notUsed.erase(a[0]);
    for (int i = 1; i < n; i++) {
        if (a[i] == a[i - 1]) {
            int mn = *notUsed.begin(), mx = *notUsed.rbegin();
            ans.push_back(mn);
            ans.push_back(mx);
            notUsed.erase(mn);
            notUsed.erase(mx);
            continue;
        }
        if (a[i] > a[i - 1]) {
            int mx = *notUsed.rbegin();
            ans.push_back(mx);
            notUsed.erase(mx);
            if (notUsed.count(a[i])) {
                ans.push_back(a[i]);
                notUsed.erase(a[i]);
            }
            else {
                mx = *notUsed.rbegin();
                ans.push_back(mx);
                notUsed.erase(mx);
            }
            continue;
        }
        int mn = *notUsed.begin();
        ans.push_back(mn);
        notUsed.erase(mn);
        if (notUsed.count(a[i])) {
            ans.push_back(a[i]);
            notUsed.erase(a[i]);
        }
        else {
            mn = *notUsed.begin();
            ans.push_back(mn);
            notUsed.erase(mn);
        }
    }
    for (auto x : ans) cout << x << " ";
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 4 ms 860 KB Output is correct
3 Correct 5 ms 1300 KB Output is correct
4 Correct 14 ms 2128 KB Output is correct
5 Correct 26 ms 3724 KB Output is correct
6 Correct 42 ms 7472 KB Output is correct
7 Correct 73 ms 11344 KB Output is correct