ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1302. Delta-wave

WA#6, please help me!! here my code
Posted by Bobur 4 Feb 2009 00:10
program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;

   var
   n, m, d, dn, dm, dns, dms, n1, m1, answer, x : integer;

   function teng(delta : integer) : integer;
   var
     ans : integer;

   begin
     ans := delta * 2;
     if odd(delta) and (odd(dn) or odd(dm)) then
       begin
         if odd(n1) then
           begin
             if odd(n) then dec(ans)
             else inc(ans)
           end
         else
           if odd(n) then inc(ans)
           else dec(ans);
       end;
     teng := ans;
   end;

begin
   read(m, n);
   if n < m then begin x := n;  n := m;  m := x;  end;
   n1 := TRUNC(sqrt(n));
   if sqr(n1)=n then dec(n1);
   m1 := TRUNC(sqrt(m));
   if sqr(m1)=m then dec(m1);
   d := n1-m1;
   dn := n - sqr(n1);
   dm := m - sqr(m1);
   dns := sqr(n1+1)-n;
   dms := sqr(m1+1)-m;
   if d = dn - dm then answer := teng(d)
   else
     begin
       if dm >= dn then begin writeLn(2*d+dm-dn);  exit  end;
       if dms >= dns then begin writeLn(2*d+dms-dns);  exit  end;
       if d > dn-dm then answer := (dn-dm)*2 + teng(d-dn+dm)
       else
         answer := (dns-dms)*2 + teng(d-dns+dms);
     end;
   writeLn(answer);
end.
Re: WA#6, please help me!! here my code
Posted by OpenGL 4 Feb 2009 01:07
Try to find other algoritm. On small test your program gives a right answers. But on this test: 119 751 answer is not true. Good luck! :)