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>
using namespace std;
int pf[1010][1010], X[50010], Y[50010];
int sum(int x, int y, int z, int t){
if (x>z || y>t) return 0;
return pf[z][t]-pf[x-1][t]-pf[z][y-1]+pf[x-1][y-1];
}
int putaway(int A, int B, int T, int _X[], int _Y[], int W[], int S[]) {
for (int i=0; i<A; ++i) X[i+1]=_X[i]-1;
for (int i=0; i<B; ++i) Y[i+1]=_Y[i]-1;
sort(X+1, X+A+1);
sort(Y+1, Y+B+1);
vector<int> vx(X+1, X+A+1), vy(Y+1, Y+B+1); vx.push_back(-1); vy.push_back(-1);
sort(vx.begin(), vx.end()); sort(vy.begin(), vy.end());
vx.resize(unique(vx.begin(), vx.end())-vx.begin());
vy.resize(unique(vy.begin(), vy.end())-vy.begin());
for (int i=1; i<=A; ++i) X[i]=lower_bound(vx.begin(), vx.end(), X[i])-vx.begin();
for (int i=1; i<=B; ++i) Y[i]=lower_bound(vy.begin(), vy.end(), Y[i])-vy.begin();
for (int i=0; i<T; ++i){
W[i]=lower_bound(vx.begin(), vx.end(), W[i])-vx.begin();
S[i]=lower_bound(vy.begin(), vy.end(), S[i])-vy.begin();
}
for (int i=0; i<T; ++i) ++pf[W[i]][S[i]];
for (int i=1; i<=1000; ++i) for (int j=1; j<=1000; ++j){
pf[i][j]+=pf[i-1][j]+pf[i][j-1]-pf[i-1][j-1];
}
int l=1, r=T;
while (l<=r){
int mid=(l+r)>>1;
bool check=1;
for (int i=0; i<=A; ++i) for (int j=0; j<=B; ++j){
if (i==A || j==B) check&=sum(X[i]+1, Y[j]+1, 1000, 1000)<=(A-i+B-j)*mid;
}
if (check) r=mid-1;
else l=mid+1;
}
return l==T+1?-1: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... |