Submission #24814

# Submission time Handle Problem Language Result Execution time Memory
24814 2017-06-14T12:04:12 Z Extazy medians (balkan11_medians) C++14
5 / 100
43 ms 3776 KB
/*
example test starts
1

5
1 3 3 4 5
example test ends
*/
#include <bits/stdc++.h>

using namespace std;

const int N = (2e5) + 7;

int n,a[N],b[N];
int up,down;
bool used[N];

void go_up() {
    while(used[up]) --up;
    used[up]=true;
}

void go_down() {
    while(used[down]) ++down;
    used[down]=true;
}

int main() {
    int tests,current_case;
    int i;

    tests=1;
    //scanf("%d", &tests);
    for(current_case=1;current_case<=tests;current_case++) {
        scanf("%d", &n);
        for(i=1;i<=n;i++) {
            scanf("%d", &b[i]);
        }
        memset(used,0,sizeof(used));
        down=0;
        up=2*n+1;
        used[down]=used[up]=true;
        a[1]=b[1];
        used[b[1]]=true;
        for(i=2;i<=n;i++) {
            if(b[i]==b[i-1]) {
                go_up();
                a[2*(i-1)]=up;
                go_down();
                a[2*(i-1)+1]=down;
            }
            else if(b[i]>b[i-1]) {
                if(!used[b[i]]) {
                    used[b[i]]=true;
                    a[2*(i-1)]=b[i];
                    go_up();
                    a[2*(i-1)+1]=up;
                }
                else {
                    go_up();
                    a[2*(i-1)]=up;
                    go_up();
                    a[2*(i-1)+1]=up;
                }
            }
            else {
                if(!used[b[i]]) {
                    used[b[i]]=true;
                    a[2*(i-1)]=b[i];
                    go_down();
                    a[2*(i-1)+1]=down;
                }
                else {
                    go_down();
                    a[2*(i-1)]=down;
                    go_down();
                    a[2*(i-1)+1]=down;
                }
            }
        }
    }
    for(i=1;i<2*n;i++) {
        if(i>1) printf(" ");
        printf("%d", a[i]);
    }

    return 0;
}

Compilation message

medians.cpp: In function 'int main()':
medians.cpp:36:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &n);
                        ^
medians.cpp:38:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &b[i]);
                               ^
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 3776 KB Integer 20 violates the range [1, 19]
2 Incorrect 0 ms 3776 KB Integer 40 violates the range [1, 39]
3 Incorrect 0 ms 3776 KB Integer 60 violates the range [1, 59]
4 Incorrect 0 ms 3776 KB Integer 80 violates the range [1, 79]
5 Incorrect 0 ms 3776 KB Integer 100 violates the range [1, 99]
6 Correct 0 ms 3776 KB Output is correct
7 Incorrect 0 ms 3776 KB Integer 140 violates the range [1, 139]
8 Incorrect 0 ms 3776 KB Integer 160 violates the range [1, 159]
9 Incorrect 0 ms 3776 KB Integer 180 violates the range [1, 179]
10 Incorrect 0 ms 3776 KB Integer 200 violates the range [1, 199]
11 Incorrect 0 ms 3776 KB Integer 600 violates the range [1, 599]
12 Incorrect 0 ms 3776 KB Integer 1200 violates the range [1, 1199]
13 Incorrect 0 ms 3776 KB Integer 2000 violates the range [1, 1999]
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 3776 KB Integer 4000 violates the range [1, 3999]
2 Incorrect 0 ms 3776 KB Integer 8000 violates the range [1, 7999]
3 Incorrect 3 ms 3776 KB Integer 16000 violates the range [1, 15999]
4 Incorrect 9 ms 3776 KB Integer 32000 violates the range [1, 31999]
5 Incorrect 19 ms 3776 KB Integer 64000 violates the range [1, 63999]
6 Incorrect 23 ms 3776 KB Integer 128000 violates the range [1, 127999]
7 Incorrect 43 ms 3776 KB Integer 200000 violates the range [1, 199999]