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];
bool check(int val){
// cout << val << endl;
fill(removed, removed + N, false);
set<pair<int, int>> s;
for (int i = 0; i < N; i++){
s.insert(MP(W[i], i));
}
priority_queue<pair<int, int>> q;
for (int i = 0; i < A; i++){
while (!s.empty() && s.begin()->first < X[i]){
int j = s.begin()->second;
q.push(MP(S[j], j));
s.erase(s.begin());
}
//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;
}
for (int i = B - 1; i >= 0; i--){
vector<pair<int, int>> vec;
for (int j = 0; j < N; j++){
if (removed[j]) continue;
if (S[j] < Y[i]) vec.emplace_back(S[j], j);
}
sort(vec.rbegin(), vec.rend());
// cout << "small #" << i + 1 << ": ";
for (int j = 0; j < vec.size(); j++){
if (j >= val) break;
int ind = vec[j].second;
removed[ind] = true;
// cout << ind + 1 << ' ';
}
// cout << endl;
}
for (int i = 0; i < N; i++){
if (!removed[i]) return false;
}
return true;
}
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];
for (int i = 0; i < N; i++) W[i] = _W[i], S[i] = _S[i];
sort(X, X + A);
sort(Y, Y + B);
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;
}
Compilation message (stderr)
robots.cpp: In function 'bool check(int)':
robots.cpp:55:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int>, std::allocator<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | for (int j = 0; j < vec.size(); j++){
| ~~^~~~~~~~~~~~
# | 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... |