제출 #298448

#제출 시각아이디문제언어결과실행 시간메모리
298448rocks03로봇 (IOI13_robots)C++14
100 / 100
1862 ms19376 KiB
#include<bits/stdc++.h>
#include "robots.h"
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define pb push_back
#define SZ(x) ((int) (x).size())
using namespace std;


vector<pii> v;
int A, B, *x, *y;
bool check(int t){
    priority_queue<int, vector<int>> pq;
    int j = 0;
    for(int i = 0; i < A; i++){
        while(j < SZ(v) && v[j].ff < x[i]){
            pq.push(v[j++].ss);
        }
        int k = t;
        while(!pq.empty() && k > 0){
            k--;
            pq.pop();
        }
    }
    while(j < SZ(v)){
        pq.push(v[j++].ss);
    }
    for(int i = B-1; i >= 0; i--){
        int k = t;
        while(!pq.empty() && k > 0 && pq.top() < y[i]){
            k--;
            pq.pop();
        }
    }
    return (pq.empty());
}

int bs(int l, int r){
    while(r - l > 1){
        int m = (l + r) / 2;
        if(check(m)){
            r = m;
        } else{
            l = m;
        }
    }
    return r;
}

int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]){
    int mxw = *max_element(X, X+A);
    int mxs = *max_element(Y, Y+B);
    for(int i = 0; i < T; i++){
        if(A > 0 && W[i] < mxw){
            continue;
        } else if(B > 0 && S[i] < mxs){
            continue;
        } else{
            return -1;
        }
    }
    ::A = A, ::B = B;
    x = X, y = Y;
    for(int i = 0; i < T; i++){
        v.pb({W[i], S[i]});
    }
    sort(v.begin(), v.end());
    sort(x, x+A);
    sort(y, y+B);
    return bs(0, T+1);
}
#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...