이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "robots.h"
#include <bits/stdc++.h>
using namespace std;
bool comp(vector< int > &A, vector< int > &B){
return A.size() < B.size();
}
vector< int > used;
bool comp1(int a, int b){
return used[a] < used[b];
}
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
if(B == 0){
sort(X,X+A);
sort(W,W+T);
for(int i = 0; i < T; i++){
if(W[i] >= X[A-1]) return -1;
}
int left = 1, right = T;
while(left < right){
int mid = (left+right)/2;
int curr = 0;
for(int i = 0; i < A; i++){
int index = min((long)curr + mid, lower_bound(W+curr, W+T, X[i])-W);
curr = index;
}
if(curr > A){
right = mid;
}else{
left = mid+1;
}
}
return right;
}
vector< int > taken(T, false);
vector< vector< int > > canTake(A+B);
used.assign(T,0);
for(int i = 0; i < A; i++){
for(int j = 0; j < T; j++){
if(W[j] < X[i]){
canTake[i].push_back(j);
used[j]++;
}
}
}
for(int i = 0; i < B; i++){
for(int j = 0; j < T; j++){
if(S[j] < Y[i]){
canTake[A+i].push_back(j);
used[j]++;
}
}
}
for(int i = 0; i < T; i++){
if(used[i] <= 0){
return -1;
}
}
sort(canTake.begin(), canTake.end(), comp);
for(int i = 0; i < A+B; i++){
sort(canTake[i].begin(), canTake[i].end(),comp1);
}
int left = 1, right = T;
while(left < right){
int mid = (left+right)/2;
for(int i = 0; i < A+B; i++){
int tot = 0;
for(int a : canTake[i]){
if(taken[a]) continue;
if(tot >= mid) break;
tot ++;
taken[a] = true;
}
}
bool verif = true;
for(int i = 0; i < T; i++){
if(!taken[i]) verif = false;
}
if(!verif){
left = mid+1;
}else{
right = mid;
}
fill(taken.begin(), taken.end(), false);
}
return right;
}
# | 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... |