Submission #147627

# Submission time Handle Problem Language Result Execution time Memory
147627 2019-08-30T10:26:49 Z zubec medians (balkan11_medians) C++14
100 / 100
112 ms 9848 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

int n, b[100100];

set<int> q;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n;
    for (int i = 1; i <= 2*n-1; i++)
        q.insert(i);
    vector <int> ans;
    for (int i = 1; i <= n; i++){
        cin >> b[i];
        if (i == 1){
            q.erase(b[i]);
            ans.push_back(b[i]);
            continue;
        }
        if (b[i] == b[i-1]){
            ans.push_back(*q.begin());
            q.erase(q.begin());
            ans.push_back(*prev(q.end()));
            q.erase(prev(q.end()));
        }
        else if (b[i] < b[i-1]){
            if (q.find(b[i]) != q.end()){
                ans.push_back(b[i]);
                q.erase(b[i]);
                ans.push_back(*q.begin());
                q.erase(q.begin());
            } else {
                ans.push_back(*q.begin());
                q.erase(q.begin());
                ans.push_back(*q.begin());
                q.erase(q.begin());
            }
        }
        else {
            if (q.find(b[i]) != q.end()){
                ans.push_back(b[i]);
                q.erase(b[i]);
                ans.push_back(*prev(q.end()));
                q.erase(prev(q.end()));
            } else {
                ans.push_back(*prev(q.end()));
                q.erase(prev(q.end()));
                ans.push_back(*prev(q.end()));
                q.erase(prev(q.end()));
            }
        }

    }
    for (int i : ans)
        cout << i << ' ';
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 380 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 604 KB Output is correct
2 Correct 5 ms 816 KB Output is correct
3 Correct 8 ms 1144 KB Output is correct
4 Correct 15 ms 1956 KB Output is correct
5 Correct 33 ms 3448 KB Output is correct
6 Correct 66 ms 6592 KB Output is correct
7 Correct 112 ms 9848 KB Output is correct