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 <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
int putaway(int A, int B, int n, int X[], int Y[], int W[], int S[]){
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;
vector<int> bs(n);
for(int i = 0; i < n; i++) bs[i] = i;
sort(bs.begin(), bs.end(), [&](int a, int b){
return S[a] < S[b];
});
vector<int> nxt(n);
for(int i = 0; i < n; i++){
nxt[i] = upper_bound(X, X+A, W[i])-X;
}
function<bool(int)> check = [&](int m){
vector<bool> marked(n, 0);
vector<int> space(A, m);
set<int> available;
for(int i = 0; i < A; i++) available.insert(i);
for(int i = n-1; i >= 0; i--){
int x = bs[i], y = nxt[x];
if(y == A) continue;
if(space[y]){
space[y]--, marked[x] = 1;
if(!space[y]) available.erase(y);
}
else{
auto it = available.upper_bound(y);
if(it == available.end()) continue;
space[*it]--, marked[x] = 1;
if(!space[*it]) available.erase(it);
}
}
int c = m, ls = B-1;
for(int i = n-1; i >= 0; i--){
if(marked[bs[i]]) continue;
if(ls < 0) return 0;
if(S[bs[i]] >= Y[ls]) return 0;
c--;
if(!c) c = m, ls--;
}
return 1;
};
int a = 1, b = n;
while(a < b){
int md = (a+b)/2;
if(check(md)) b = md;
else a = md+1;
}
return a;
}
# | 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... |