Submission #931523

#TimeUsernameProblemLanguageResultExecution timeMemory
93152312345678Robots (IOI13_robots)C++17
100 / 100
1771 ms23000 KiB
#include "robots.h"
#include <bits/stdc++.h>

using namespace std;

const int nx=1e6+5;

int l=1, r=nx, d[nx];
vector<pair<int, int>> w, s;

int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
    sort(X, X+A);
    sort(Y, Y+B);
    w.push_back({INT_MAX, T});
    s.push_back({INT_MAX, T});
    for (int i=0; i<T; i++) w.push_back({W[i], i}), s.push_back({S[i], i});
    sort(w.begin(), w.end());
    sort(s.begin(), s.end());
    while (l<r)
    {
        int md=(l+r)/2, p=0, cnt=0;
        priority_queue<pair<int, int>> pq;
        for (int i=0; i<T; i++) d[i]=0;
        for (int i=0; i<A; i++)
        {
            while (w[p].first<X[i]) pq.push({S[w[p].second], w[p].second}), p++;
            int tmp=md;
            while (tmp>0&&!pq.empty()) cnt++, d[pq.top().second]=1, pq.pop(), tmp--;
        }
        while (!pq.empty()) pq.pop();
        p=0;
        for (int i=0; i<B; i++)
        {
            while (s[p].first<Y[i]||d[s[p].second])
            {
                if (d[s[p].second]) p++;
                else pq.push({W[s[p].second], s[p].second}), p++;
            }
            int tmp=md;
            while (tmp>0&&!pq.empty()) cnt++, d[pq.top().second]=1, pq.pop(), tmp--;
        }
        if (cnt==T) r=md;
        else l=md+1;
    }
    return (l==nx)?-1: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...