# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
769431 | boris_mihov | Robots (IOI13_robots) | C++17 | 1 ms | 340 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 <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::multiset <int> vals;
int check(int times, int X[], int Y[])
{
vals.clear();
int ptr = 0;
int cntDestroyed = 0;
for (int curr = 0 ; curr < a ; ++curr)
{
while (ptr + 1 <= n && wX[ptr + 1] <= X[curr])
{
ptr++;
vals.insert(sX[ptr]);
}
for (int t = 0 ; t < times && vals.size() ; ++t)
{
vals.erase(std::prev(vals.end()));
}
}
while (ptr + 1 <= n)
{
ptr++;
vals.insert(sX[ptr]);
}
for (int curr = 0 ; curr < b && vals.size() ; ++curr)
{
for (int t = 0 ; t < times && vals.size() ; ++t)
{
auto it = vals.upper_bound(Y[curr]);
if (it == vals.begin())
{
break;
} else
{
it = std::prev(it);
vals.erase(it);
}
}
}
return vals.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 + 1, permX + 1 + n, 1);
std::sort(permX + 1, permX + 1 + n, [&](const int &a, const int &b)
{
return W[a] < W[b];
});
for (int i = 1 ; 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 = 1 ; 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... |