이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "robots.h"
#include <algorithm>
#include <iostream>
#include <cassert>
#include <numeric>
#include <set>
using namespace std;
int putaway(int wrobot, int srobot, int n, int rw[], int rs[], int w[], int s[]) {
sort(rw, rw + wrobot);
sort(rs, rs + srobot);
auto comp_w = [&](int i, int j)->bool{ return w[i] < w[j]; };
auto comp_s = [&](int i, int j)->bool{ return s[i] < s[j]; };
int* byw = new int[n];
int* bys = new int[n];
iota(byw, byw + n, 0);
iota(bys, bys + n, 0);
sort(byw, byw + n, comp_w);
sort(bys, bys + n, comp_s);
auto check = [&](int time)->bool {
cout <<time << endl;
int* done = new int[n];
{
int toy = 0;
set<pair<int,int>> st;
for (int rob = 0; rob < wrobot; rob++) {
while (toy < n && w[byw[toy]] < rw[rob]) {
st.insert({-s[toy], toy});
toy++;
}
for (int rem = 0; rem < time && st.size(); rem++) {
done[st.begin()->second] = 1;
st.erase(st.begin());
}
}
}
{
int toy = 0;
set<pair<int,int>> st;
for (int rob = 0; rob < srobot; rob++) {
while (toy < n && s[bys[toy]] < rs[rob]) {
if (!done[toy])
st.insert({-w[toy], toy});
toy++;
}
for (int rem = 0; rem < time && st.size(); rem++) {
done[st.begin()->second] = 1;
st.erase(st.begin());
}
}
}
int all_done = accumulate(done, done + n, 0);
return all_done == n;
};
int l = -1, r = n +1;
while (l < r - 1) {
int mid = (l + r) / 2;
if (check(mid)) r = mid;
else l = mid;
}
return r == n+1 ? -1 : r;
}
# | 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... |