Submission #3615711


Source Code Expand

program AT842;
 uses math;
 var
  x,y,b:array[0..100001] of longint;
  i,k,m,n,o,p,mc:longint;
 function hahacmp(x,y:longint):boolean;
  begin
   exit(x<y);
  end;
 procedure hahaswap(var x,y:longint);
  var
   t:longint;
  begin
   t:=x;
   x:=y;
   y:=t;
  end;
 procedure haha(l,r:longint);
  var
   o,p,m,t:longint;
  begin
   o:=l;
   p:=r;
   m:=x[(l+r)>>1];
   repeat
    while hahacmp(x[o],m) do inc(o);
    while hahacmp(m,x[p]) do dec(p);
    if o>p then break;
    hahaswap(x[o],x[p]);
    hahaswap(y[o],y[p]);
    inc(o);
    dec(p);
   until o>p;
   if o<r then haha(o,r);
   if l<p then haha(l,p);
  end;
 procedure hahaup(k:longint);
  begin
   while k>1 do
    begin
     if hahacmp(b[k>>1],b[k]) then break;
     hahaswap(b[k],b[k>>1]);
     k:=k>>1;
    end;
  end;
 procedure hahadown(k,w:longint);
  var
   p:longint;
  begin
   while k<<1<=w do
    begin
     p:=k<<1;
     if hahacmp(b[p+1],b[p]) and (p+1<=w) then inc(p);
     if hahacmp(b[k],b[p]) then break;
     hahaswap(b[p],b[k]);
     k:=p;
    end;
  end;
 function hahaseki(z:longint):boolean;
  var
   xc,yc,o,p,s,l:longint;
  begin
   s:=0;
   xc:=0;
   yc:=k;
   p:=0;
   o:=1;
   while p+z<=m do
    begin
     while (o<=n) and (x[o]<=p+z) do
      begin
       inc(s);
       b[s]:=y[o];
       hahaup(s);
       inc(o);
      end;
     if s=0 then
      begin
       if yc=0 then exit(false);
       p:=xc;
       dec(yc);
       continue;
      end;
     l:=b[1];
     hahaswap(b[1],b[s]);
     hahadown(1,s-1);
     dec(s);
     xc:=max(xc,l);
     if l<p then continue;
     if l>p+z then p:=p+z
              else p:=l;
    end;
   exit(true);
  end;
 begin
  readln(n,m,k);
  for i:=1 to n do
   readln(x[i],y[i]);
  haha(1,n);
  o:=1;
  p:=m+1;
  while o<=p do
   begin
    mc:=(o+p)>>1;
    if hahaseki(mc) then p:=mc-1
                    else o:=mc+1;
   end;
  writeln(o);
 end.

Submission Info

Submission Time
Task G - 夏休みの掃除当番
User dictoy
Language Pascal (FPC 2.6.2)
Score 200
Code Size 1986 Byte
Status AC
Exec Time 611 ms
Memory 1408 KB

Compile Error

/usr/bin/ld.bfd: warning: ./link.res contains output sections; did you forget -T?

Judge Result

Set Name Small Large
Score / Max Score 50 / 50 150 / 150
Status
AC × 15
AC × 39
Set Name Test Cases
Small sample01, small-hand00, small-hand01, small-random00, small-random01, small-random02, small-random03, small-random04, small-random05, small-random06, small-random07, small-random08, small-random09, small-random10, small-random11
Large sample02, sample03, large-hand00, large-hand01, large-hand02, large-hand03, large-hand04, large-random00, large-random01, large-random02, large-random03, large-random04, large-random05, large-random06, large-random07, large-random08, large-random09, large-random10, large-random11, large-random12, large-random13, large-random14, sample01, sample02, sample03, small-hand00, small-hand01, small-random00, small-random01, small-random02, small-random03, small-random04, small-random05, small-random06, small-random07, small-random08, small-random09, small-random10, small-random11
Case Name Status Exec Time Memory
large-hand00 AC 1 ms 128 KB
large-hand01 AC 1 ms 128 KB
large-hand02 AC 166 ms 1152 KB
large-hand03 AC 166 ms 1152 KB
large-hand04 AC 162 ms 1152 KB
large-random00 AC 484 ms 1280 KB
large-random01 AC 483 ms 1280 KB
large-random02 AC 472 ms 1408 KB
large-random03 AC 367 ms 1280 KB
large-random04 AC 465 ms 1408 KB
large-random05 AC 524 ms 1280 KB
large-random06 AC 385 ms 1280 KB
large-random07 AC 549 ms 1280 KB
large-random08 AC 530 ms 1280 KB
large-random09 AC 527 ms 1280 KB
large-random10 AC 514 ms 1280 KB
large-random11 AC 441 ms 1280 KB
large-random12 AC 602 ms 1408 KB
large-random13 AC 473 ms 1280 KB
large-random14 AC 449 ms 1280 KB
sample01 AC 1 ms 128 KB
sample02 AC 1 ms 128 KB
sample03 AC 0 ms 128 KB
small-hand00 AC 1 ms 128 KB
small-hand01 AC 165 ms 1152 KB
small-random00 AC 400 ms 1280 KB
small-random01 AC 365 ms 1280 KB
small-random02 AC 400 ms 1280 KB
small-random03 AC 483 ms 1280 KB
small-random04 AC 448 ms 1280 KB
small-random05 AC 466 ms 1280 KB
small-random06 AC 529 ms 1280 KB
small-random07 AC 450 ms 1280 KB
small-random08 AC 489 ms 1280 KB
small-random09 AC 610 ms 1280 KB
small-random10 AC 611 ms 1280 KB
small-random11 AC 610 ms 1280 KB