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];
set < ii > s;
vector < int > v;
bool f(int x) {
s.clear();
v.clear();
for(int i = 0; i < A; i++)
s.insert(ii(X[i], x));
for(int i = n - 1; i >= 0; i--) {
type(s) it = s.lower_bound(ii(a[i].first + 1, 0));
if(it != s.end()) {
int st = it -> first;
int nd = it -> second;
s.erase(it);
if(nd - 1)
s.insert(ii(st, nd - 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);
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... |