# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
592472 | fuad27 | Robots (IOI13_robots) | C++17 | 3073 ms | 51544 KiB |
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 putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
if(B == 0) {
sort(X, X+A);
int lo = 0, hi = 2*A;
int res=-1;
while(lo <= hi) {
int mid = (lo+hi)/2;
vector<int> v(A);
for(int i = 0;i<T;i++) {
int it = upper_bound(X, X+A, W[i])-X;
if(it == A)return -1;
v[it]++;
}
for(int i = 0;i<A-1;i++) {
if(v[i] > mid) {
v[i+1]+=v[i]-mid;
v[i]=mid;
}
}
if(v.back() > mid) {
lo = mid+1;
}
else {
res=mid;
hi=mid-1;
}
}
return res;
}
sort(X, X+A);
sort(Y, Y+B);
int lo = 1, hi = T;
int res=-1;
while(lo <= hi) {
int mid = (lo+hi)/2;
multiset<int> v[A];
multiset<int> rem2;
for(int i = 0;i<T;i++) {
int it = upper_bound(X, X+A, W[i])-X;
if(it == A)rem2.insert(S[i]);
else v[it].insert(S[i]);
}
multiset<int> rem;
for(int i = 0;i<A;i++) {
while(v[i].size() > mid) {
auto it = v[i].begin();
rem.insert(*it);
v[i].erase(it);
}
while(rem.size()>0 and v[i].size() < mid) {
auto it = rem.end();
--it;
v[i].insert(*it);
rem.erase(it);
}
while(rem.size() and v[i].size() and (*(--rem.end())) > (*v[i].begin())) {
auto it = (--rem.end());
auto it2 = v[i].begin();
v[i].insert(*it);
rem.insert(*it2);
rem.erase(it);
v[i].erase(it2);
}
}
for(auto it=rem2.begin();it!=rem2.end();it++) {
rem.insert(*it);
}
vector<int> v2(B);
for(auto it=rem.begin();it!=rem.end();++it) {
int val = (*it);
int idx=upper_bound(Y, Y+B, val)-Y;
if(idx==B)return -1;
v2[idx]++;
}
for(int i = 0;i<B-1;i++) {
if(v2[i] > mid) {
int c = v2[i]-mid;
v2[i+1]+=c;
v2[i]=mid;
}
}
if(v2.back() > mid) {
lo = mid+1;
}
else {
res=mid;
hi = mid-1;
}
}
return res;
}
Compilation message (stderr)
# | 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... |