Submission #104857

#TimeUsernameProblemLanguageResultExecution timeMemory
104857popovicirobertRobots (IOI13_robots)C++14
76 / 100
3093 ms16736 KiB
#include "robots.h"
#include <bits/stdc++.h>

using namespace std;

struct Comp {
    int val, pos;
    bool operator <(const Comp &other) const {
        return val < other.val;
    }
};

vector <int> ordw, ords;
vector <bool> vis;

inline bool check(int res, int A, int B, int T, int X[], int Y[], int W[], int S[]) {
    fill(vis.begin(), vis.end(), 0);
    priority_queue <Comp> pq;

    int pos = 0, ans = 0;
    for(int i = 0; i < A; i++) {
        while(pos < T && W[ordw[pos]] < X[i]) {
            pq.push({S[ordw[pos]], ordw[pos]});
            pos++;
        }
        for(int j = 1; j <= res && pq.size(); j++) {
            auto it = pq.top();
            pq.pop();
            vis[it.pos] = 1;
            ans++;
        }
    }
    pos = 0;
    int cnt = 0;
    for(int i = 0; i < B; i++) {
        while(pos < T && S[ords[pos]] < Y[i]) {
            if(vis[ords[pos]] == 0) {
                cnt++;
            }
            pos++;
        }
        for(int j = 1; j <= res && cnt > 0; j++) {
            ans++;
            cnt--;
        }
    }
    return ans == T;
}

int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
    sort(X, X + A);
    sort(Y, Y + B);
    ordw.resize(T), ords.resize(T), vis.resize(T);
    iota(ordw.begin(), ordw.end(), 0), iota(ords.begin(), ords.end(), 0);
    sort(ordw.begin(), ordw.end(), [&](const int &a, const int &b) {return W[a] < W[b];});
    sort(ords.begin(), ords.end(), [&](const int &a, const int &b) {return S[a] < S[b];});

    int res = 0;
    for(int step = 1 << 20; step; step >>= 1) {
        if(!check(res + step, A, B, T, X, Y, W, S)) {
            res += step;
        }
    }
    res++;
    return check(res, A, B, T, X, Y, W, S) ? res : -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...