Submission #39710

# Submission time Handle Problem Language Result Execution time Memory
39710 2018-01-17T14:38:48 Z MladenP medians (balkan11_medians) C++14
5 / 100
13 ms 2760 KB
#include<bits/stdc++.h>
#define STIZE(x) fprintf(stderr, "STIZE%d\n", x);
#define PRINT(x) fprintf(stderr, "%s = %d\n", #x, x);
#define NL(x) printf("%c", " \n"[(x)]);
#define lld long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define endl '\n'
#define mid (l+r)/2
#define all(a) begin(a),end(a)
#define sz(a) int((a).size())
#define LINF 1000000000000000000LL
#define INF 1000000000
#define EPS 1e-9
using namespace std;
#define MAXN 100010
int n, b[MAXN], l, r;
bool pos[2*MAXN];
void upd() {
    while(l < r && pos[l]) l++;
    while(l < r && pos[r]) r--;
}
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> b[i];
    l = 1, r = 2*n-1, pos[b[1]] = 1;
    cout << b[1] << ' ';
    for(int i = 2; i <= n; i++) {
        upd();
        if(b[i] == b[i-1]) {
            pos[l] = pos[r] = 1;
            cout << l << ' ' << r << ' ';
        } else if(b[i] > b[i-1]) {
            if(pos[b[i]]) {
                cout << r << ' ';
                pos[r] = 1;
                upd();
                cout << r << ' ';
            } else {
                pos[b[i]] = pos[r] = 1;
                cout << b[i] << ' ' << r << ' ';
            }
        } else {
            if(pos[b[i]]) {
                cout << l << ' ';
                pos[l] = 1;
                upd();
                cout << l << ' ';
            } else {
                pos[b[i]] = pos[l] = 1;
                cout << b[i] << ' ' << l << ' ';
            }
        }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 2760 KB Not a permutation
2 Incorrect 0 ms 2760 KB Not a permutation
3 Incorrect 0 ms 2760 KB Not a permutation
4 Incorrect 0 ms 2760 KB Not a permutation
5 Incorrect 0 ms 2760 KB Not a permutation
6 Correct 0 ms 2760 KB Output is correct
7 Incorrect 0 ms 2760 KB Not a permutation
8 Incorrect 0 ms 2760 KB Not a permutation
9 Incorrect 0 ms 2760 KB Not a permutation
10 Incorrect 0 ms 2760 KB Not a permutation
11 Incorrect 0 ms 2760 KB Not a permutation
12 Incorrect 0 ms 2760 KB Not a permutation
13 Runtime error 0 ms 2760 KB Execution killed because of forbidden syscall writev (20)
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 2760 KB Execution killed because of forbidden syscall writev (20)
2 Runtime error 0 ms 2760 KB Execution killed because of forbidden syscall writev (20)
3 Runtime error 0 ms 2760 KB Execution killed because of forbidden syscall writev (20)
4 Runtime error 0 ms 2760 KB Execution killed because of forbidden syscall writev (20)
5 Runtime error 3 ms 2760 KB Execution killed because of forbidden syscall writev (20)
6 Runtime error 6 ms 2760 KB Execution killed because of forbidden syscall writev (20)
7 Runtime error 13 ms 2760 KB Execution killed because of forbidden syscall writev (20)