Submission #27493

# Submission time Handle Problem Language Result Execution time Memory
27493 2017-07-13T07:52:16 Z TAMREF medians (balkan11_medians) C++11
100 / 100
126 ms 12568 KB
#include <bits/stdc++.h>
using namespace std;
const int mx=100005;
int B[mx], A[mx<<1];
int N;
set<int> L;
void input(){
    scanf("%d",&N);
    for(int i=0;i<N;i++){
        scanf("%d",&B[i]);
    }
    for(int i=0;i<2*N-1;i++) L.insert(i+1);
}
void solve(){
    L.erase(B[0]);
    A[0]=B[0];
    for(int i=1;i<N;i++){
        if(B[i]==B[i-1]){
            A[2*i-1]=*L.begin(); L.erase(*L.begin());
            A[2*i  ]=*L.rbegin(); L.erase(*L.rbegin());
        }
        else if(B[i]<B[i-1]){
            if(L.find(B[i])==L.end()){
                A[2*i-1]=*L.begin(); L.erase(*L.begin());
                A[2*i  ]=*L.begin(); L.erase(*L.begin());
            }else{
                A[2*i-1]=B[i]; L.erase(B[i]);
                A[2*i  ]=*L.begin(); L.erase(*L.begin());
            }
        }
        else{
            if(L.find(B[i])==L.end()){
                A[2*i-1]=*L.rbegin(); L.erase(*L.rbegin());
                A[2*i  ]=*L.rbegin(); L.erase(*L.rbegin());
            }else{
                A[2*i-1]=B[i]; L.erase(B[i]);
                A[2*i  ]=*L.rbegin(); L.erase(*L.rbegin());
            }
        }
    }
}
int main(){
    input();
    solve();
    for(int i=0;i<2*N-1;i++) printf("%d ",A[i]);
    return 0&puts("");
}

Compilation message

medians.cpp: In function 'void input()':
medians.cpp:8:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&N);
                   ^
medians.cpp:10: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 3196 KB Output is correct
2 Correct 0 ms 3196 KB Output is correct
3 Correct 0 ms 3196 KB Output is correct
4 Correct 0 ms 3196 KB Output is correct
5 Correct 0 ms 3196 KB Output is correct
6 Correct 0 ms 3196 KB Output is correct
7 Correct 0 ms 3196 KB Output is correct
8 Correct 0 ms 3196 KB Output is correct
9 Correct 0 ms 3196 KB Output is correct
10 Correct 0 ms 3196 KB Output is correct
11 Correct 0 ms 3196 KB Output is correct
12 Correct 0 ms 3328 KB Output is correct
13 Correct 0 ms 3328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 3460 KB Output is correct
2 Correct 3 ms 3592 KB Output is correct
3 Correct 6 ms 3988 KB Output is correct
4 Correct 19 ms 4648 KB Output is correct
5 Correct 29 ms 6232 KB Output is correct
6 Correct 76 ms 9268 KB Output is correct
7 Correct 126 ms 12568 KB Output is correct