This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("Ofast,O2")
#pragma GCC target("avx,avx2")
#include "robots.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 3e2;
#define MP make_pair
int A, B, N, X[MAXN], Y[MAXN], W[MAXN], S[MAXN];
bool removed[MAXN];
vector<int> p1, p2;
bool check(int val){
// cout << val << endl;
fill(removed, removed + N, false);
int idx = 0;
priority_queue<pair<int, int>> q;
for (int i = 0; i < A; i++){
while (idx < N && W[p1[idx]] < X[i]){
int j = p1[idx++];
q.push(MP(S[j], j));
}
//cout << "weak #" << i + 1 << ": ";
int cur = val;
while (cur-- && !q.empty()){
int x = q.top().second;
q.pop();
removed[x] = true;
// cout << x + 1 << ' ';
}
// cout << endl;
}
vector<int> v;
for (int i : p2){
if (!removed[i]) v.push_back(S[i]);
}
for (int i = B - 1; i >= 0; i--){
int cur = val;
while (cur-- && !v.empty()){
if (v.back() >= Y[i]) return false;
v.pop_back();
}
}
return v.empty();
}
int putaway(int _A, int _B, int _N, int _X[], int _Y[], int _W[], int _S[]) {
A = _A, B = _B, N = _N;
for (int i = 0; i < A; i++) X[i] = _X[i];
for (int i = 0; i < B; i++) Y[i] = _Y[i];
p1.resize(N), p2.resize(N);
for (int i = 0; i < N; i++){
W[i] = _W[i];
S[i] = _S[i];
p1[i] = p2[i] = i;
}
sort(X, X + A);
sort(Y, Y + B);
sort(p1.begin(), p1.end(), [](int i, int j){
return W[i] < W[j];
});
sort(p2.begin(), p2.end(), [](int i, int j){
return S[i] < S[j];
});
int l = 1, r = N;
int ans = -1;
while (l <= r){
int mid = (l + r) >> 1;
if (check(mid)){
ans = mid;
r = mid - 1;
} else l = mid + 1;
}
return ans;
}
# | 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... |