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>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include "robots.h"
#define DEBUGGING
using namespace std;
constexpr static int DEBUG_PRINT_SIZE = 10;
void __print(int i) { cerr << i; }
void __print(const char* c) { cerr << c; }
void __print(int* i) { cerr << "{"; for (int j = 0; j < DEBUG_PRINT_SIZE; j++) { cerr << (j ? ", " : ""); __print(i[j]); } cerr << "}"; }
template<typename T>
void __print(T& t) { cerr << "{"; int f = 0; for (auto& i : t) { cerr << (f++ ? ", " : ""); __print(i); } cerr << "}"; }
void _print() { cerr << "]\n"; }
template<typename T, typename... V>
void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); }
#ifdef DEBUGGING
#define debug(x...) cerr << "[" << (#x) << "] = ["; _print(x)
#else
#define debug(x...)
#endif
bool is_possible(int a, int b, int t, int x[], int y[], int k);
int ceil_div(int a, int b);
constexpr static int MXTOYSIZE = 1e6;
array<int, 2> v[MXTOYSIZE];
int putaway(int a, int b, int t, int x[], int y[], int ww[], int ss[])
{
for (int i = 0; i < t; i++)
v[i] = {ww[i], ss[i]};
sort(v, v + t);
sort(x, x + a);
sort(y, y + b);
int l = 0, r = t+1;
while (r - l > 1)
{
int m = l+r>>1;
if (is_possible(a, b, t, x, y, m))
r = m;
else
l = m;
}
if (r == t+1)
return -1;
return r;
}
constexpr static int MXSIZE = 50000;
int ycounts[MXSIZE];
bool insert_to_ycounts(int y[], int b, int val);
bool is_possible(int a, int b, int t, int x[], int y[], int k)
{
for (int i = 0; i < b; i++)
ycounts[i] = 0;
int j = t-1;
while (j >= 0 && v[j][0] >= x[a-1])
if (!insert_to_ycounts(y, b, v[j--][1]))
return false;
multiset<int> m;
for (int i = a-1; i >= 0; i--)
{
while (j >= 0 && (i == 0 || v[j][0] >= x[i-1])) m.insert(v[j--][1]);
while (ceil_div(m.size(), a - i) > k)
if (!insert_to_ycounts(y, b, *m.begin()))
return false;
else
m.erase(m.begin());
}
int prefix = 0;
for (int i = b-1; i >= 0; i--)
{
prefix += ycounts[i];
if (ceil_div(prefix, b - i) > k)
return false;
}
return true;
}
bool insert_to_ycounts(int y[], int b, int val)
{
int index = upper_bound(y, y + b, val) - y;
if (index == b)
return false;
ycounts[index]++;
return true;
}
int ceil_div(int a, int b)
{
return (a + b - 1) / b;
}
Compilation message (stderr)
robots.cpp: In function 'int putaway(int, int, int, int*, int*, int*, int*)':
robots.cpp:41:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
41 | int m = l+r>>1;
| ~^~
# | 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... |