Submission #310475

#TimeUsernameProblemLanguageResultExecution timeMemory
310475talant117408Robots (IOI13_robots)C++17
100 / 100
1915 ms19316 KiB
#include "robots.h"
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair <ll, ll> pii;
 
#define precision(n) fixed << setprecision(n)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define eps (double)1e-9
#define PI 2*acos(0.0)
#define endl "\n"
#define sz(v) (int)(v).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define MAX_A 50005
#define MAX_B 50005
#define MAX_T 500005

int x[MAX_A], y[MAX_B], a, b, t;
pii toys[MAX_T];

bool check(int m){
    priority_queue <int> K;
    int i, tt;
    for(i = 0, tt = 0; i <= a; i++){
        for(;tt < t && toys[tt].first < x[i]; tt++)
            K.push(toys[tt].second);
        if(i != a)
            for(int j = 0; j < m && (!K.empty()); j++)
                K.pop();
    }
    
    for(i = b-1; i >= 0 && !K.empty() && K.top() < y[i]; i--){
        for(int j = 0; j < m && !K.empty(); j++) K.pop();
    }
    
    return K.empty();
}

int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
    
    a = A; b = B;
    t = T;
    copy(X, X+a, x);
    copy(Y, Y+b, y);
    x[a] = 2e9+5;
    for(int i = 0; i < t; i++)
        toys[i] = {W[i], S[i]};
        
    sort(x, x+a);
    sort(y, y+b);
    sort(toys, toys+t);
    
    int l = 1, r = t;
    while(l < r){
        int mid = (l+r) >> 1;
        if(check(mid)) r = mid;
        else l = mid+1;
    }
    if(!check(l)) return -1;
    return l;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...