Submission #674049

# Submission time Handle Problem Language Result Execution time Memory
674049 2022-12-22T17:50:26 Z Ahmed57 medians (balkan11_medians) C++14
5 / 100
63 ms 7372 KB
#include <bits/stdc++.h>

using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ordered_set s;
    int n;cin>>n;
    int l = 1 , r = 2*n-1;
    int vis[2*n] = {0};
    for(int i = 1;i<=n;i++){
        long long x;cin>>x;
        if(i==1){
            cout<<x<<" ";
            s.insert(x);
            vis[x] = 1;
            continue;
        }
        int c = s.order_of_key(x);
        int rem = (2*(i-1)-1)-c;
        if(vis[x])rem--;
        if(c>rem){
            vis[x] = 1;
            while(vis[r])r--;
            s.insert(r);
            s.insert(x);
            vis[r] = 1;
            cout<<r--<<" ";
            cout<<x<<" ";
        }else if(rem>c){
            vis[x] = 1;
            while(vis[l])l++;
            s.insert(l);
            s.insert(x);
            vis[l] = 1;
            cout<<l++<<" ";
            cout<<x<<" ";
        }else{
            while(vis[l])l++;
            while(vis[r])r--;
            vis[l] = 1;
            vis[r] = 1;
            s.insert(l);
            s.insert(r);
            cout<<l++<<" ";
            cout<<r--<<" ";
        }
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Not a permutation
2 Incorrect 0 ms 212 KB Not a permutation
3 Incorrect 0 ms 212 KB Not a permutation
4 Incorrect 0 ms 212 KB Not a permutation
5 Incorrect 1 ms 212 KB Not a permutation
6 Correct 0 ms 212 KB Output is correct
7 Incorrect 0 ms 212 KB Not a permutation
8 Incorrect 0 ms 212 KB Not a permutation
9 Incorrect 1 ms 320 KB Not a permutation
10 Incorrect 1 ms 212 KB Not a permutation
11 Incorrect 1 ms 340 KB Not a permutation
12 Incorrect 1 ms 340 KB Not a permutation
13 Incorrect 1 ms 340 KB Not a permutation
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 468 KB Not a permutation
2 Incorrect 3 ms 596 KB Not a permutation
3 Incorrect 5 ms 852 KB Not a permutation
4 Incorrect 10 ms 1492 KB Not a permutation
5 Incorrect 20 ms 2516 KB Not a permutation
6 Incorrect 42 ms 4832 KB Not a permutation
7 Incorrect 63 ms 7372 KB Not a permutation