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>
using namespace std;
#define type(x) __typeof((x).begin())
#define foreach(it, x) for(type(x) it = (x).begin(); it != (x).end(); it++)
typedef long long ll;
typedef pair < int, int > ii;
const int inf = 1e9 + 333;
const ll linf = 1e18 + inf;
#include "robots.h"
const int N = 1e6 + 5;
int n;
int A, B;
int X[N], Y[N];
ii a[N];
int id[N], root[N], size[N];
vector < int > v;
int dsu(int x) {
if(x == root[x])
return x;
return root[x] = dsu(root[x]);
}
bool f(int x) {
v.clear();
for(int i = 0; i <= A; i++) {
root[i] = i;
size[i] = x;
}
for(int i = n - 1; i >= 0; i--) {
int go = dsu(id[i]);
if(go < A) {
size[go]--;
if(!size[go]) {
root[go] = go + 1;
}
}
else {
v.push_back(a[i].second);
}
}
int ptr = 0;
for(int i = B - 1; i >= 0; i--) {
int rem = x;
while(ptr < v.size() and rem and Y[i] > v[ptr]) {
rem--;
ptr++;
}
}
return ptr == v.size();
}
int putaway(int A, int B, int n, int X[], int Y[], int W[], int S[]) {
:: n = n;
:: A = A;
:: B = B;
sort(X, X + A);
sort(Y, Y + B);
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++) {
a[i] = ii(S[i], W[i]);
}
sort(a, a + n);
for(int i = 0; i < n; i++)
swap(a[i].first, a[i].second);
for(int i = 0; i < n; i++) {
id[i] = upper_bound(X, X + A, a[i].first) - X;
}
if(!f(n))
return -1;
int l = 1, r = n;
while(l < r) {
int m = l + r >> 1;
if(f(m))
r = m;
else
l = m + 1;
}
return l;
}
# | 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... |