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>
#define ll long long
using namespace std;
vector<pair<int,int>> Tw,Ts;
int a, b, t;
vector<int> x, y;
bool bcheck(int n){
int pos=0,cnt=n,toys_cnt=0;
vector<bool> Tbool(t,0);
for(int i=0; i < t; i++){
if(Tw[i].first < x[pos]){
cnt--;
toys_cnt++;
Tbool[Tw[i].second] = 1;
}
if(cnt == 0){
cnt = n;
pos++;
}
if(pos >= a)break;
}
if(b == 0)return toys_cnt == t;
pos = 0;
for(int i=0; i < t; i++){
if(Ts[i].first < y[pos] && !Tbool[Ts[i].second]){
cnt--;
toys_cnt++;
Tbool[Ts[i].second] = 1;
}
if(cnt == 0){
cnt = n;
pos++;
}
if(pos >= a)break;
}
return toys_cnt == t;
}
int binary(int l, int r){
int n;
while(l <= r){
n = (l+r)/2;
if(bcheck(n)){
r = n-1;
}else{
l = n+1;
}
}
return l;
}
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
int ans=-1;
if(T == 2 && A+B == 2){
for(int i=0; i < T; i++){
Tw.push_back({W[i],S[i]});
Ts.push_back({S[i],W[i]});
}
sort(Tw.rbegin(),Tw.rend());
sort(Ts.rbegin(),Ts.rend());
int r1=0,r2=0;
if(A == 2){
for(int i=0; i < T; i++){
if(Tw[i].first < X[0]){
r1++;
}
if(Tw[i].first < X[1]){
r2++;
}
}
}else if(B == 2){
for(int i=0; i < T; i++){
if(Ts[i].first < Y[0]){
r1++;
}
if(Ts[i].first < Y[1]){
r2++;
}
}
}else{
for(int i=0; i < T; i++){
if(Tw[i].first < X[0]){
r1++;
}
}
for(int i=0; i < T; i++){
if(Ts[i].first < Y[0]){
r2++;
}
}
}
ans=-1;
if((r1 == 2 && r2 >= 1) || (r2 == 2 && r1 >= 1)){
ans = 1;
}else if((r1 == 2 && r2 == 0) || (r2 == 2 && r1 == 0)){
ans = 2;
}else if(r1 == 1 && r2 == 1){
int a,b;
for(int i=0; i < T; i++){
if(Tw[i].first < X[0]){
a = i;
}
if(Tw[i].second < Y[0]){
b = i;
}
}
if(a != b){
ans = 1;
}
}
return ans;
}
a = A; b = B; t = T;
for(int i=0; i < A; i++){
x.push_back(X[i]);
}
sort(x.rbegin(),x.rend());
for(int i=0; i < B; i++){
y.push_back(Y[i]);
}
sort(y.rbegin(),y.rend());
for(int i=0; i < T; i++){
Tw.push_back({W[i],i});
Ts.push_back({S[i],i});
}
sort(Tw.rbegin(),Tw.rend());
sort(Ts.rbegin(),Ts.rend());
ans=binary(1,T);
if(ans > T)ans = -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... |