제출 #473615

#제출 시각아이디문제언어결과실행 시간메모리
473615dung11112003로봇 (IOI13_robots)C++11
100 / 100
1279 ms30532 KiB
#include "robots.h"
#include <bits/stdc++.h>

#define taskname ""
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define for0(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex <ld> cd;
typedef vector <cd> vcd;
typedef vector <int> vi;

template<class T> using v2d = vector <vector <T> >;
template<class T> bool uin(T &a, T b)
{
    return a > b ? (a = b, true) : false;
}
template<class T> bool uax(T &a, T b)
{
    return a < b ? (a = b, true) : false;
}

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());



int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[])
{
    sort(X, X + A);
    sort(Y, Y + B);
    vector <int> posA(T), posB(T);
    for (int i = 0; i < T; i++)
    {
        posA[i] = upper_bound(X, X + A, W[i]) - X;
        posB[i] = upper_bound(Y, Y + B, S[i]) - Y;
        if (posA[i] == A && posB[i] == B)
        {
            return -1;
        }
    }
    auto check = [&](int mx) -> bool
    {
        vector <vector <int>> a(A);
        vector <int> b(B);
        for (int i = 0; i < T; i++)
        {
            if (posA[i] == A)
            {
                //forced
                //move to B
                b[posB[i]]++;
            }
            else
            {
                //move to A?
                a[posA[i]].push_back(posB[i]);
            }
        }
        priority_queue <int, vector <int>, greater <int>> pq;
        long long lim = 0;
        for (int i = A - 1; i >= 0; i--)
        {
            lim += mx;
            for (auto &pos: a[i])
            {
                pq.push(pos);
            }
            while ((int)pq.size() > lim)
            {
                int pos = pq.top();
                pq.pop();
                if (pos == B)
                {
                    return 0;
                }
                b[pos]++;
            }
        }
        lim = 0;
        int sum = 0;
        for (int i = B - 1; i >= 0; i--)
        {
            lim += mx;
            sum += b[i];
            if (sum > lim)
            {
                return 0;
            }
        }
        return 1;
    };
    int lo = -1, hi = T;
    while (hi - lo > 1)
    {
        int mid = (lo + hi) / 2;
        if (check(mid))
        {
            hi = mid;
        }
        else
        {
            lo = mid;
        }
    }
    return hi;
}
#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...