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>
#include "robots.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 1 << 20;
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()
#define fillchar(a, s) memset((a), (s), sizeof(a))
void compress (vector<int> &v) {
sort(all(v));
v.resize(unique(all(v)) - v.begin());
}
int A, B, N;
int *X, *Y, *W, *S;
pii T[MAXN];
int heap[MAXN], *hend;
bool moo (int g) {
if (g * ll(A + B) < N) {
return false;
}
hend = heap;
//memory limit is so fucking strict...i don't even understand
//and then you need a TLE sol...wtf??
int ptr = 0;
for (int i = 0; i < A; i++) {
//insert stuff in
for (; ptr < N && T[ptr].fi < X[i]; ptr++) {
*(hend++) = T[ptr].se;
push_heap(heap, hend);
}
for (int taken = 0; hend != heap && taken < g; taken++) {
pop_heap(heap, (hend--));
}
}
for (; ptr < N; ptr++) {
*(hend++) = T[ptr].se;
push_heap(heap, hend);
}
//by now you don't even care about weight.
for (int i = B - 1; i >= 0; i--) {
//if ur stuck
if (heap != hend && *heap >= Y[i]) {
return false;
}
for (int taken = 0; hend != heap && taken < g; taken++) {
pop_heap(heap, (hend--));
}
}
return hend == heap;
}
int putaway (int aaa, int bbb, int nnn, int xxx[], int yyy[], int www[], int sss[]) {
A = aaa;
B = bbb;
N = nnn;
X = xxx;
Y = yyy;
W = www;
S = sss;
sort(X, X + A);
sort(Y, Y + B);
for (int i = 0; i < N; i++) {
if (W[i] >= X[A - 1] && S[i] >= Y[B - 1]) {
return -1;
}
T[i] = pii(W[i], S[i]);
}
sort(T, T + N);
//memory is the issue here
int lo = 0, hi = N;
while (hi - lo > 1) {
int mid = (lo + hi) / 2;
if (moo(mid)) {
hi = mid;
} else {
lo = mid;
}
}
return hi;
}
# | 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... |