Submission #1149035

#TimeUsernameProblemLanguageResultExecution timeMemory
1149035_callmelucianRobots (IOI13_robots)C++17
100 / 100
783 ms15016 KiB
#include <bits/stdc++.h>
using namespace std;

#ifndef LOCAL
    #include "robots.h"
#endif // LOCAL

using ll = long long;
using ld = long double;
using pl = pair<ll,ll>;
using pii = pair<int,int>;
using tpl = tuple<int,int,int>;

#define all(a) a.begin(), a.end()
#define filter(a) a.erase(unique(all(a)), a.end())

const int mn = 1e6 + 6;
int strong[mn], big[mn];
pii toy[mn];

bool ok (int tryTime, int n, int m, int tc) {
    priority_queue<int, vector<int>, greater<int>> pq;
    vector<int> undone;

    int process = 0;
    for (int i = 0; i < n; i++) {
        int debt = 0;
        while (process < tc && toy[process].first >= strong[i]) {
            pq.push(toy[process].second), debt++, process++;
        }
        while (debt--) {
            assert(pq.size());
            undone.push_back(pq.top()), pq.pop();
        }
        for (int j = 0; j < tryTime && process < tc; j++, process++) pq.push(toy[process].second);
    }
    for (; process < tc; process++) undone.push_back(toy[process].second);
    sort(all(undone), greater<int>());

    process = 0;
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < tryTime && process < undone.size(); j++, process++)
            if (undone[process] >= big[i]) return 0;
    }
    return process == undone.size();
}

int putaway (int A, int B, int T, int X[], int Y[], int W[], int S[]) {
    /// transfer input
    for (int i = 0; i < A; i++) strong[i] = X[i];
    for (int i = 0; i < B; i++) big[i] = Y[i];
    for (int i = 0; i < T; i++) toy[i] = {W[i], S[i]};

    /// sort
    sort(strong, strong + A, greater<int>());
    sort(big, big + B, greater<int>());
    sort(toy, toy + T, greater<pii>());

    /// binary search
    int ans = 0;
    for (int mask = 1 << 19; mask; mask >>= 1)
        if (!ok(ans | mask, A, B, T)) ans |= mask;
    return (ans == (1 << 20) - 1 ? -1 : ans + 1);
}

#ifdef LOCAL
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    int A = 3, B = 2, T = 10;
    int X[3] = {6, 2, 9};
    int Y[2] = {4, 7};
    int W[10] = {4, 8, 2, 7, 1, 5, 3, 8, 7, 10};
    int S[10] = {6, 5, 3, 9, 8, 1, 3, 7, 6, 5};

//    int A = 2, B = 1, T = 3;
//    int X[2] = {2, 5};
//    int Y[1] = {2};
//    int W[3] = {3, 5, 2};
//    int S[3] = {1, 3, 2};

//    int A = 5, B = 3, T = 8;
//    int X[5] = {5, 10, 15, 20, 25};
//    int Y[3] = {5, 10, 15};
//    int W[8] = {4, 9, 14, 19, 24, 100, 100, 100};
//    int S[8] = {100, 100, 100, 100, 100, 4, 9, 14};

    cout << putaway(A, B, T, X, Y, W, S);

    return 0;
}
#endif // LOCAL
#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...