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 1116. Piecewise Constant Function

Look here!!!
Posted by Crash_access_violation 1 Jun 2008 23:00
Why my algo don't get AC???
On all tests in the forum, my algo give RIGHT ANSWERS.
I don't understand why my algo got WA#10.
Please give me one contrtest.

my algo :

CONST
 inf  = 1111;
 MaxN = 32000;
 fin  = '';
 fout = '';

TYPE
 integer = Longint;
 Point = Record
  L, R, Y : integer;
 End;

VAR
 N, Li, Ri, Yi, id : integer;
 D : Array [1 .. MaxN] of Point;
 A, B, C : Array [- MaxN .. MaxN] of integer;

PROCEDURE Init;
 Var
  i : integer;
   Begin
    for i := - MaxN to MaxN do
     begin
      A[i] := inf;
      B[i] := inf;
      C[i] := inf;
     end;
   End;

PROCEDURE ColorA;
 Var
  i : integer;
   Begin
    for i := Li to Ri do
     A[i] := Yi;
   End;

PROCEDURE ColorB;
 Var
  i : integer;
   Begin
    for i := Li to Ri do
     B[i] := Yi;
   End;

PROCEDURE ColorC;
 Var
  i : integer;
   Begin
    for i := Li to Ri do
     C[i] := Yi;
   End;

PROCEDURE In_Data;
 Var
  i : integer;
   Begin
    Init;
    Read(N);
     for i := 1 to N do
      begin
       Read(Li, Ri, Yi);
        if (A[Li] = inf) and (A[Ri] = inf) and (A[Li - 1] = inf) then
          ColorA
            else
        if (B[Li] = inf) and (B[Ri] = inf) and (B[Li - 1] = inf) then
          ColorB
            else
          ColorC;
      end;
   End;

PROCEDURE Find;
   Begin
    while id < Li do
     begin
      if (A[id] <> inf) and (A[id + 1] <> inf) and (A[id] = A[id + 1]) then
        begin
         inc(N);
         D[N].L := id;
         D[N].Y := A[id];
          while (id < Li) and (A[id] = A[id + 1]) do
           inc(id);
         D[N].R := id;
          if D[N].L = D[N].R then
            dec(N);
        end;
      if (B[id] <> inf) and (B[id + 1] <> inf) and (B[id] = B[id + 1]) then
        begin
         inc(N);
         D[N].L := id;
         D[N].Y := B[id];
          while (id < Li) and (B[id] = B[id + 1]) do
           inc(id);
         D[N].R := id;
          if D[N].L = D[N].R then
            dec(N);
        end;
      if (C[id] <> inf) and (C[id + 1] <> inf) and (C[id] = C[id + 1]) then
        begin
         inc(N);
         D[N].L := id;
         D[N].Y := C[id];
          while (id < Li) and (C[id] = C[id + 1]) do
           inc(id);
         D[N].R := id;
          if D[N].L = D[N].R then
            dec(N);
        end;
       inc(id);
     end;
   End;

PROCEDURE Solve;
 Var
  i, M : integer;
   Begin
    Read(M);
    id := - MaxN;
    N := 0;
     for i := 1 to M do
      begin
       Read(Li, Ri, Yi);
       Find;
       id := Ri;
      end;
    if id < MaxN then
      begin
       Li := MaxN;
       Find;
      end;
   End;

PROCEDURE Out_Data;
 Var
  i : integer;
   Begin
    Write(N);
     for i := 1 to N do
      Write(' ', D[i].L, ' ', D[i].R, ' ', D[i].Y);
   End;

BEGIN
 In_Data;
 Solve;
 Out_Data;
END.

Thanks.
Re: Look here!!!
Posted by Crash_access_violation 8 Mar 2009 22:17
Admins please show me test#10. My mail : [crashvio(dog).mail.by]. I resolve my solution many times. My algo give right answers on all tests in forum. Maybe test 10 is wrong? Thanks.