이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "robots.h"
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define V vector
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << "LINE(" << __LINE__ << ") -> " << #x << " is " << (x) << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;
const int INF = 1e9 + 7;
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
vi a(A), b(B);
V<pi> c(T);
for(int i = 0; i < A; i++) a[i] = X[i];
for(int i = 0; i < B; i++) b[i] = Y[i];
for(int i = 0; i < T; i++) c[i] = MP(W[i], S[i]);
sort(ALL(a)), sort(ALL(b)), sort(ALL(c), [&] (pi a, pi b) {
return a.S < b.S;
});
auto noB = [&] () {
sort(W, W + T);
int mx = 0;
for(int i = T - 1, j = A - 1; i >= 0; i--) {
while(j >= 0 && a[j] > W[i]) j--;
int have = T - i, can = A - 1 - j;
mx = max(mx, (have + can - 1) / can);
}
return mx;
};
if(B == 0) return noB();
auto ok = [&] (int k) { // each people can kill at msot k things
set<pi> ms, ms2;
for(int i = A - 1; i >= 0; i--) ms.insert({a[i], i});
for(int i = B - 1; i >= 0; i--) ms2.insert({b[i], i});
vi cnt(A), cnt2(B);
for(int i = T - 1; i >= 0; i--) {
int x = c[i].F, y = c[i].S;
if(ms.size() && ms.upper_bound(MP(x, INF)) != ms.end()) {
auto it = ms.upper_bound(MP(x, INF));
cnt[it -> S]++;
if(cnt[it -> S] == k) ms.erase(it);
} else {
if(ms2.empty() || ms2.upper_bound(MP(y, INF)) == ms2.end())
return false;
auto it = ms2.upper_bound(MP(y, INF));
cnt2[it -> S]++;
if(cnt2[it -> S] == k) ms2.erase(it);
}
}
return true;
};
int lb = 1, rb = T;
while(lb <= rb) {
int mb = (lb + rb) / 2;
if(ok(mb)) rb = mb - 1;
else lb = mb + 1;
}
if(lb > T) return -1;
return lb;
}
# | 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... |