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 <bits/stdc++.h>
#include "robots.h"
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
bool Test(int x, int A, int B, int T, int *X, int *Y, const vector<pair<int, int>> &Toy)
{
if ((long long)x*(A+B) < T) return 0;
int idT = 0, idA = 0;
multiset<int> remain;
while (idT < T && idA < A)
{
if (X[idA] <= Toy[idT].first)
{
int remov = x;
if (remov >= remain.size()) remain.clear(), remov = 0;
while (remov > 0) remain.erase(prev(remain.end())), remov--;
idA++;
}
else remain.insert(Toy[idT++].second);
}
while (idT < T) remain.insert(Toy[idT++].second);
while (idA < A)
{
int remov = x;
if (remov >= remain.size()) remain.clear(), remov = 0;
while (remov > 0) remain.erase(prev(remain.end())), remov--;
idA++;
}
auto idR = remain.begin(); int idB = 0;
int cnt = 0;
while (idR != remain.end() && idB < B)
{
if (Y[idB] <= *idR) cnt = max(0, cnt-x), idB++;
else cnt++, idR++;
}
if (idR != remain.end()) return 0;
while (idB < B) cnt = max(0, cnt-x), idB++;
return (cnt == 0);
}
int putaway(int A, int B, int T, int X[], int Y[], int _W[], int _S[])
{
srand(time(0));
if (rand()%2) swap(A, B), swap(X, Y), swap(_W, _S);
vector<pair<int, int>> Toy(T);
for (int i = 0; i < T; i++) Toy[i] = make_pair(_W[i], _S[i]);
sort(X, X+A); sort(Y, Y+B);
for (int i = 0; i < T; i++) if (Toy[i].first >= X[A-1] && Toy[i].second >= Y[B-1]) return -1;
sort(Toy.begin(), Toy.end());
int ini = 1, fim = T;
while (ini < fim)
{
int m = (ini + fim) >> 1;
if (Test(m, A, B, T, X, Y, Toy)) fim = m;
else ini = m+1;
}
return fim;
}
Compilation message (stderr)
robots.cpp: In function 'bool Test(int, int, int, int, int*, int*, const std::vector<std::pair<int, int> >&)':
robots.cpp:17:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::multiset<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | if (remov >= remain.size()) remain.clear(), remov = 0;
| ~~~~~~^~~~~~~~~~~~~~~~
robots.cpp:27:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::multiset<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | if (remov >= remain.size()) remain.clear(), remov = 0;
| ~~~~~~^~~~~~~~~~~~~~~~
# | 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... |