Submission #1149032

#TimeUsernameProblemLanguageResultExecution timeMemory
1149032_callmelucianRobots (IOI13_robots)C++17
28 / 100
319 ms12656 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[j] >= 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);
}
#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...