This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "robots.h"
#include <bits/stdc++.h>
using namespace std;
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<vector<int>> pts(B+1);
vector<int> init_up(A+1), init_right(B+1);
for (int i=0; i<T; i++){
int x = upper_bound(X, X+A, W[i]) - X;
int y = upper_bound(Y, Y+B, S[i]) - Y;
if (x == A && y == B) return -1;
else if (x == A) ++init_right[y];
else if (y == B) ++init_up[x];
else pts[y].push_back(x);
}
for (auto &v : pts) sort(v.begin(), v.end());
auto try_answer = [&] (int k) {
auto up = init_up, right = init_right;
priority_queue<int> pq;
for (int i=0; i<B; i++) {
for (int j : pts[i]) pq.push(j);
while (!pq.empty() && right[i] < k) {
int j = pq.top(); pq.pop();
++right[i];
}
if (right[i] > k) {
right[i+1] += right[i] - k;
right[i] = k;
}
}
while (!pq.empty()) {
int j = pq.top(); pq.pop();
++up[j];
}
for (int j=0; j<A; j++) {
if (up[j] > k) {
up[j+1] += up[j] - k;
up[j] = k;
}
}
// cout << k << " -> " << (up[A] == 0 && right[B] == 0) << endl;
return up[A] == 0 && right[B] == 0;
};
int l = 0, r = T;
while ((r-l) > 1) {
int m = (l+r) / 2;
if (try_answer(m)) r = m;
else l = m;
}
return r;
}
Compilation message (stderr)
robots.cpp: In lambda function:
robots.cpp:33:21: warning: unused variable 'j' [-Wunused-variable]
33 | int j = pq.top(); pq.pop();
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |