# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
769440 | boris_mihov | Robots (IOI13_robots) | C++17 | 659 ms | 23972 KiB |
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 <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <vector>
#include <bitset>
#include <queue>
#include <set>
typedef long long llong;
const int MAXN = 1000000 + 10;
const int MAXAB = 50000 + 10;
int n;
int a, b;
int wX[MAXN];
int sX[MAXN];
int permX[MAXN];
std::priority_queue <int> pq;
int check(int times, int X[], int Y[])
{
while (!pq.empty()) pq.pop();
int ptr = -1;
int cntDestroyed = 0;
for (int curr = 0 ; curr < a ; ++curr)
{
while (ptr + 1 < n && wX[ptr + 1] <= X[curr])
{
ptr++;
pq.push(sX[ptr]);
}
for (int t = 0 ; t < times && pq.size() ; ++t)
{
pq.pop();
}
}
while (ptr + 1 < n)
{
ptr++;
pq.push(sX[ptr]);
}
for (int curr = b - 1 ; curr >= 0 && pq.size() ; --curr)
{
for (int t = 0 ; t < times && pq.size() ; ++t)
{
if (Y[curr] < pq.top()) return false;
pq.pop();
}
}
return pq.empty();
}
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[])
{
a = A;
b = B;
n = T;
std::iota(permX, permX + n, 0);
std::sort(permX, permX + n, [&](const int &a, const int &b)
{
return W[a] < W[b];
});
for (int i = 0 ; i < n ; ++i)
{
wX[i] = W[permX[i]] + 1;
sX[i] = S[permX[i]] + 1;
}
std::sort(X, X + a);
std::sort(Y, Y + b);
for (int i = 0 ; i < n ; ++i)
{
if (wX[i] > X[a - 1] && sX[i] > Y[b - 1])
{
return -1;
}
}
// std::cout << "byW\n";
// for (int i = 1 ; i <= n ; ++i)
// {
// std::cout << w[sortedX.perm[i]] << ' ' << s[sortedX.perm[i]] << '\n';
// }
// std::cout << "byS\n";
// for (int i = 1 ; i <= n ; ++i)
// {
// std::cout << w[sortedY.perm[i]] << ' ' << s[sortedY.perm[i]] << '\n';
// }
int pw = -1;
while (!check(1 << pw + 1, X, Y)) pw++;
int l = (pw == -1 ? 0 : (1 << pw)), r = (1 << pw + 1), mid;
while (l < r - 1)
{
mid = (l + r) / 2;
if (!check(mid, X, Y)) l = mid;
else r = mid;
}
return r;
}
Compilation message (stderr)
# | 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... |