이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
#include"robots.h"
#ifdef mlocal
#include "grader.c"
#endif
using namespace std;
#define for_(i, s, e) for (int i = s; i < (int) e; i++)
#define for__(i, s, e) for (ll i = s; i < e; i++)
typedef long long ll;
typedef vector<int> vi;
typedef array<int, 2> ii;
#define endl '\n'
int a, b, t;
vi ct;
vector<bool> done;
vector<ii> toys;
bool check(int box, int wlim[], int slim[]) {
done.assign(t, false);
ct.assign(b, box);
set<ii> s;
int rem = t;
for_(i, 0, b) s.insert({slim[i], i});
for_(i, 0, t) {
auto pt = s.lower_bound({toys[i][1], -1});
if (pt != s.end()) {
done[i] = true;
rem--;
if (ct[(*pt)[1]] == 1) s.erase(pt);
else ct[(*pt)[1]] -= 1;
}
}
int pt = 0, ct;
for_(i, 0, a) {
ct = 0;
while (pt < t and ct < box) {
if (!done[pt] and toys[pt][0] <= wlim[i]) {
ct++;
rem--;
done[pt] = true;
}
pt++;
}
}
return !rem;
}
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
a = A, b = B, t = T;
toys.reserve(T);
for_(i, 0, a) X[i] -= 1;
for_(i, 0, b) Y[i] -= 1;
for_(i, 0, t) toys.push_back({W[i], S[i]});
sort(X, X+a, greater<>());
sort(Y, Y+a, greater<>());
sort(toys.rbegin(), toys.rend());
for_(i, 0, t) if ((a == 0 or toys[i][0] > X[0]) and (b == 0 or toys[i][1] > Y[0])) return -1;
int l = 1, r = T+1, ans = r;
while (l < r) {
int mid = (l+r)/2;
bool fin = check(mid, X, Y);
if (fin) {
ans = r = mid;
} else l = mid+1;
}
return ans;
}
# | 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... |