이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "robots.h"
#include<bits/stdc++.h>
#define F first
#define S second
typedef long long ll;
using namespace std;
int n;
int a,b;
int robs[100010];
int robw[100010];
int weight[1000010];
int sizz[1000010];
int done[1000010];
bool check1(int x,int siz){
int l=0;
int j=0;
int cur=0;
while (l<n){
if (cur==x){
cur=0;
j++;
if (siz&&j==b)return 0;
if (!siz&&j==a)return 0;
}
if (siz){
if (sizz[l]<robs[j]){
l++;
cur++;
}else {
j++;
cur=0;
if (j==b)return 0;
}
continue;
}
if (weight[l]<robw[j]){
l++;
cur++;
}else {
j++;
cur=0;
if (j==a)return 0;
}
}
return 1;
}
int bs1(int siz){
int st=1;
int en=n;
int mid;
int ans=n;
while (st<=en){
mid=(st+en)/2;
if (check1(mid,siz)){
en=mid-1;
ans=mid;
}else {
st=mid+1;
}
}
return ans;
}
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
a=A;b=B;n=T;
for (int i=0;i<A;i++){
robw[i]=X[i];
}
for (int i=0;i<B;i++){
robs[i]=Y[i];
}
for (int i=0;i<n;i++){
weight[i]=W[i];
sizz[i]=S[i];
}
sort(weight,weight+n);
sort(sizz,sizz+n);
sort(robs,robs+b);
sort(robw,robw+a);
for (int i=0;i<n;i++){
if (W[i]>=robw[a-1]&&S[i]>=robs[b-1]){
return -1;
}
}
if (B==0){
return bs1(0);
}
if (A==0){
return bs1(1);
}
if (A+B==2&&T==2){
if (robw[0]>W[0]&&robs[0]>S[1])return 1;
if (robw[0]>W[1]&&robs[0]>S[0])return 1;
return 2;
}
int ans=0;
while (1){
int l=0;
int r=0;
int ch=0;
while (l+r<A+B){
pair<int,int> mxs={-1,0},mxw={-1,0};
for (int i=0;i<n&&l<A;i++){
if (done[i])continue;
if (W[i]<robw[l]){
mxs=max(mxs,{S[i],i});
}
}
if (mxs.F!=-1){
ch=1;
done[mxs.S]=1;
}
for (int i=0;i<n&&r<B;i++){
if (done[i])continue;
if (S[i]<robs[r]){
mxw=max(mxw,{W[i],i});
}
}
if (mxw.F!=-1){
ch=1;
done[mxw.S]=1;
}
r++;
if (r>B)r=B;
l++;
if (l>A)l=A;
}
if (ch==0)return -1;
ans++;
int b=1;
for (int i=0;i<n;i++){
if (done[i]==0)b=0;
}
if (b)return ans;
}
return ans;
}
/*
int main (){
int A,B,T;
int X[100010];
int Y[100010];
int W[100010];
int S[100010];
cin >>A>>B>>T;
for (int i=0;i<A;i++){
cin >>X[i];
}
for (int i=0;i<B;i++){
cin >>Y[i];
}
for (int i=0;i<T;i++){
cin >>W[i]>>S[i];
}
cout <<putaway(A,B,T,X,Y,W,S)<<endl;
return 0;
}
*/
# | 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... |