이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "robots.h"
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
int t,i,n,m,x[1010101],y[1010101],hs,l,r,c,xx[1010101],yy[1010101],b[1010101],st[1010101];
pair<int,int> a[1010101];
void un(ll aa,ll bb,ll cc,ll dd,ll ee)
{
if(aa==bb)
st[ee]=dd;
else
{
ll ce=(aa+bb)/2;
if(cc<=ce)
un(aa,ce,cc,dd,ee*2);
else
un(ce+1,bb,cc,dd,ee*2+1);
st[ee]=min(st[ee*2],st[ee*2+1]);
}
}
ll hn(ll aa,ll bb,ll cc,ll dd,ll ee)
{
if(bb<cc||dd<aa)
return 1;
else
if(cc<=aa&&bb<=dd)
return st[ee];
else
{
ll ce=(aa+bb)/2;
return min(hn(aa,ce,cc,dd,ee*2),hn(ce+1,bb,cc,dd,ee*2+1));
}
}
bool cm(pair<ll,ll> aa,pair<ll,ll> bb)
{
return aa.se>bb.se;
}
bool rmt(ll aa)
{
ll ii,jj,le,re,hv1,ce,hv2;
for(ii=0;ii<n;ii++)
{
xx[ii]=0;
un(0,n-1,ii,0,1);
}
for(ii=0;ii<m;ii++)
yy[ii]=0;
for(ii=0;ii<t;ii++)
b[ii]=0;
for(ii=0;ii<t;ii++)
{
le=0;
re=n-1;
hv1=-1;
while(le<=re)
{
ce=(le+re)/2;
if(a[ii].fi<x[ce])
{
hv1=ce;
re=ce-1;
}
else
le=ce+1;
}
if(hv1!=-1)
{
le=hv1;
re=n-1;
hv2=-1;
while(le<=re)
{
ce=(le+re)/2;
if(hn(0,n-1,hv1,ce,1)==0)
{
hv2=ce;
re=ce-1;
}
else
le=ce+1;
}
if(hv2!=-1)
{
b[ii]=1;
// cout<<hv2<<" ";
xx[hv2]++;
if(xx[hv2]==aa)
{
un(0,n-1,hv2,1,1);
// cout<<hn(0,n-1,hv2,hv2,1)<<"hv\n";
}
}
}
}
// cout<<"\n";
// for(ii=0;ii<n;ii++)
// cout<<xx[ii]<<" ";
// cout<<aa<<"\n";
for(ii=0;ii<m;ii++)
un(0,m-1,ii,0,1);
for(ii=0;ii<t;ii++)
{
if(b[ii]==0)
{
le=0;
re=m-1;
hv1=-1;
while(le<=re)
{
ce=(le+re)/2;
if(a[ii].se<y[ce])
{
hv1=ce;
re=ce-1;
}
else
le=ce+1;
}
if(hv1!=-1)
{
hv2=-1;
le=hv1;
re=m-1;
while(le<=re)
{
ce=(le+re)/2;
if(hn(0,m-1,hv1,ce,1)==0)
{
hv2=ce;
re=ce-1;
}
else
le=ce+1;
}
if(hv2!=-1)
{
b[ii]=1;
yy[hv2]++;
if(yy[hv2]==aa)
un(0,m-1,hv2,1,1);
}
}
}
if(b[ii]==0)
{
return 0;
}
}
return 1;
}
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
t=T;
for(i=0;i<T;i++)
a[i]=mp(W[i],S[i]);
n=A;
m=B;
for(i=0;i<A;i++)
x[i]=X[i];
for(i=0;i<B;i++)
y[i]=Y[i];
sort(a,a+T,cm);
sort(x,x+A);
sort(y,y+B);
hs=-1;
l=1;
r=T;
while(l<=r)
{
c=(l+r)/2;
if(rmt(c))
{
hs=c;
r=c-1;
}
else
l=c+1;
}
return hs;
}
컴파일 시 표준 에러 (stderr) 메시지
robots.cpp: In function 'bool rmt(long long int)':
robots.cpp:44:8: warning: unused variable 'jj' [-Wunused-variable]
ll ii,jj,le,re,hv1,ce,hv2;
^
# | 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... |