Submission #31568

# Submission time Handle Problem Language Result Execution time Memory
31568 2017-08-29T16:29:11 Z ngkan146 medians (balkan11_medians) C++
100 / 100
29 ms 3384 KB
#include <bits/stdc++.h>
using namespace std;
int n;
int a[200005];
int b[100005];
int mi,ma;
bool used[200005];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&b[i]);
    mi = 1, ma = 2*n-1;
    a[1] = b[1];
    used[a[1]] = 1;
    for(int i=2;i<=n;i++){
        if (b[i] == b[i-1]){
            while(used[mi]) ++mi;
            a[2*i-2] = mi;
            used[mi] = 1;
            while(used[ma]) --ma;
            a[2*i-1] = ma;
            used[ma] = 1;
        }
        else if (b[i] < b[i-1]){
            if (used[b[i]]){
                while(used[mi]) ++mi;
                a[2*i-2] = mi;
                used[mi] = 1;
                while(used[mi]) ++mi;
                a[2*i-1] = mi;
                used[mi] = 1;
            }
            else{
                while(used[mi]) ++mi;
                a[2*i-2] = mi;
                used[mi] = 1;
                a[2*i-1] = b[i];
                used[b[i]] = 1;
            }
        }
        else{
            if (used[b[i]]){
                while(used[ma]) --ma;
                a[2*i-2] = ma;
                used[ma] = 1;
                while(used[ma]) --ma;
                a[2*i-1] = ma;
                used[ma] = 1;
            }
            else{
                while(used[ma]) --ma;
                a[2*i-2] = ma;
                used[ma] = 1;
                a[2*i-1] = b[i];
                used[b[i]] = 1;
            }
        }
    }
    for(int i=1;i<=2*n+-1;i++)
        printf("%d ",a[i]);
}

Compilation message

medians.cpp: In function 'int main()':
medians.cpp:9:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
                   ^
medians.cpp:11:26: 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 Correct 0 ms 3384 KB Output is correct
2 Correct 0 ms 3384 KB Output is correct
3 Correct 0 ms 3384 KB Output is correct
4 Correct 0 ms 3384 KB Output is correct
5 Correct 0 ms 3384 KB Output is correct
6 Correct 0 ms 3384 KB Output is correct
7 Correct 0 ms 3384 KB Output is correct
8 Correct 0 ms 3384 KB Output is correct
9 Correct 0 ms 3384 KB Output is correct
10 Correct 0 ms 3384 KB Output is correct
11 Correct 0 ms 3384 KB Output is correct
12 Correct 0 ms 3384 KB Output is correct
13 Correct 0 ms 3384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 3384 KB Output is correct
2 Correct 0 ms 3384 KB Output is correct
3 Correct 3 ms 3384 KB Output is correct
4 Correct 6 ms 3384 KB Output is correct
5 Correct 6 ms 3384 KB Output is correct
6 Correct 16 ms 3384 KB Output is correct
7 Correct 29 ms 3384 KB Output is correct