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 1452. Pascal vs. C++

WA 8:(((
Posted by THE_SCORPION 13 Sep 2006 20:48
Why WA 8? Please help me ! I tested my programm many times, but did'not find a mistake. Maybe someone tell me where is wrong or give me same test.
Sorry for my bad english.

Here is my code:
program Project2;

{$APPTYPE CONSOLE}
uses windows;
type din=array of longint;
type IntMas=array[1..2000] of longint;
var mas,mas2:din;
    pre,rez:intMas;
    n,i,dlin,dlin2,kol,u,y,save,KOLM,a,b,sr,MAX,num,del,l,r:longint;
    f:text;
   // lMas:array[1..2000,1..2000] of longint;
   DELTA:array[0..1000000000] of boolean;
    T:BOOLEAN;
    t1,t2,t3,t4:_SYSTEMTIME;



procedure sort(var d,d2:din;var l:longint);
var dlin,dlin2:longint;
     mas2,mas3,Dmas2,Dmas3:din;
begin
t:=false;


dlin:=l div 2;
dlin2:=l-dlin;
setlength(mas2,dlin+1);
setlength(Dmas2,dlin+1);
for i:=1 to dlin do
  mas2[i]:=d[i];
for i:=1 to dlin do
  Dmas2[i]:=d2[i];

setlength(mas3,dlin2+1);
setlength(Dmas3,dlin2+1);
for i:=1 to dlin2 do
  mas3[i]:=d[i+dlin];
for i:=1 to dlin2 do
  Dmas3[i]:=d2[i+dlin];

if dlin>1 then
  begin
  sort(mas2,Dmas2,dlin);
  end;

if dlin2>1 then
  begin
  sort(mas3,Dmas3,dlin2);
  end;
kol:=0;
i:=1;
u:=1;
L:=dlin+dlin2;
while kol<l do
  begin

  if mas2[i]<mas3[u] then
    begin
    inc(kol);
    d[kol]:=mas2[i];
    d2[kol]:=Dmas2[i];
    if i+1<=dlin then
      inc(i)
    else
      begin
      for y:=u to dlin2 do
        begin
        d[kol+y-u+1]:=mas3[y];
        d2[kol+y-u+1]:=Dmas3[y];

        end;
      break;
      end;
    end
  else
    begin
    inc(kol);
    d[kol]:=mas3[u];
    d2[kol]:=Dmas3[u];
    if u+1<=dlin2 then
      inc(u)
    else
      begin
      for y:=i to dlin do
        begin
        d[kol+y-i+1]:=mas2[y];
        d2[kol+y-i+1]:=Dmas2[y];
        end;
      break;
      end;
    end
  end;

//sort()
end;

begin
{assign(f,'input.txt');
reset(f);}
readln({f,}n);



setlength(mas,n+1);
setlength(mas2,n+1);
for i:=1 to n do
  begin
  read({f,}mas[i]);
  mas2[i]:=i;
  end;

t:=false;
if n>1 then
sort(mas,mas2,n);

rez[1]:=1;
kolM:=1;
DELTA[0]:=true;

for i:=1 to n do
  for u:=i+1 to n do
    if not DELTA[mas[u]-mas[i]] then
      begin
      del:=mas[u]-mas[i];
      DELTA[del]:=true;
      num:=mas[u];
      num:=num+del;

      kol:=2;
      pre[1]:=mas2[u];
      pre[2]:=mas2[i];
      l:=u;
      r:=n;
      while true do
        begin
        if mas[l]=num then
          begin

          inc(kol);
          pre[kol]:=mas2[l];
          num:=num+del;
          l:=l;
          r:=n;
       //   break;
          end;

        if mas[r]=num then
          begin

          inc(kol);
          pre[kol]:=mas2[r];
          num:=num+del;
          l:=r;
          r:=n;
         // break;
          end;
        if (mas[r]<>num) and(mas[l]<>num) then
          begin
          if ((abs(r-l)=1) or (abs(r-l)=0))   then
            begin
            if kol>kolM then
              begin
              for l:=1 to kol do
                rez[l]:=pre[l];
              kolm:=kol;
              end;
            break;
            end;
          if mas[(l+r)div 2]<num then
            l:=(l+r)div 2
          else
            r:=(l+r)div 2;
          end;



        end;

      end;


writeln(kolM);
for i:=1 to kolM do
  begin
  write(rez[i]);
  write(' ');

  end;
  //readln;

end.
Re: WA 8:(((
Posted by r1d1 2 Feb 2010 00:09
9
1 3 5 11 2 3 4 7 9
answer:
6
1 2 3 8 9 4