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 1642. 1D Maze

WA 1
Posted by rodge(Vologda ML) 18 Oct 2009 17:11
var
  a : array[-1000..0] of integer;
  b : array[0..1000] of integer;
  n, i, j, k, l, m, u, x : integer;
  c : array[1..100] of integer;
begin
  read(n, x);
  k := 0;
  m := 0;
  l := 0;
  u := 0;
  j := 0;
  i := 0;
  for i := 1 to n do begin
    read(c[i]);
    if c[i] >= 0 then b[c[i]] := 1 else a[c[i]] := 1;
  end;
  if b[0] = 1 then u := 1;
  if x = 0 then begin
    k := 0;
    m := 0;
  end;
  if x < 0 then begin
    for i := x to -1 do begin
      if a[i] = 1 then begin
        u := 1;
        break;
      end;
    end;
    if i = 0 then begin
      for j := 0 downto x do begin
        inc(m);
      end;
      m := m - 1;
      repeat
        inc(k);
      until b[k] = 1;
      k := 2 * k + m;
      end;
  end;
  if x > 0 then begin
      for i := 0 to x do begin
        if(b[i]) = 1 then begin
          u := 1;
          break;
        end;
      end;
      if i = x + 1 then begin
        for j := 0 to x do begin
          inc(k);
        end;
        k := k - 1;
        repeat
          inc(m);
          dec(l);
        until a[l] = 1;
        m := 2 * m + k
      end;
    end;
    if u = 1 then writeln('Impossible') else
    writeln(k,' ', m);
    readln;
    readln;
end.
my code it is work for different numbers and tests (my tests( but WA 1) plese, who can help me?
Re: WA 1
Posted by Oleg Strekalovsky aka OSt [Vologda SPU] 18 Oct 2009 18:14
I solved this problem by emulation.
I have WA 1 too. Problem was with calculation distance. They some times became negative. When i add function abs() for every places, where was calculation distances - i got AC


Edited by author 18.10.2009 18:20
Re: WA 1
Posted by rodge(Vologda ML) 8 Nov 2009 13:51
var
  a : array[-1000..0] of integer;
  b : array[0..1000] of integer;
  n, i, j, k, l, m, u, x : integer;
  c : array[1..100] of integer;
begin
  read(n, x);
  k := 0;
  m := 0;
  l := 0;
  u := 0;
  j := 0;
  i := 0;
  for i := 1 to n do begin
    read(c[i]);
    if c[i] > 0 then b[c[i]] := 1 else a[c[i]] := 1;
  end;
  if x < 0 then begin
    for i := x to -1 do begin
      if a[i] = 1 then begin
        u := 1;
        break;
      end;
    end;
    if i = 0 then begin
      j := 0;
      while (k>x) do begin
        dec(k);
      end;
      k := abs(k);
      while (b[j]<>1) and (abs(j)<1000) do begin
        inc(m);
        inc(j);
      end;
      m := m * 2 + k;
    end;
  end;
  if x > 0 then begin
    for i := 0 to x do begin
      if(b[i]) = 1 then begin
        u := 1;
        break;
      end;
    end;
    if i = x + 1 then begin
      j := 0;
      while m < x do begin
        inc(m);
      end;
      while (a[j]<>1) and (abs(j)<1000) do begin
        inc(k);
        dec(j);
      end;
      k := k * 2 + m;
    end;
  end;
  if u = 1 then writeln('Impossible') else begin
    write(m,' ',k);
  end;
  readln;readln;
end.
correct my solution but WA1 it's very bad ((( who knows test 1?

Edited by author 08.11.2009 14:04
Re: WA 1
Posted by rodge(Vologda ML) 8 Nov 2009 14:05
all tests is right may be I wrong in output? can somebody help me and sorry for my bad english
Re: WA 1
Posted by unlucky [Vologda SPU] 8 Nov 2009 15:54
rodge(Vologda ML) wrote 8 November 2009 13:51
var
  a : array[-1000..0] of integer;
  b : array[0..1000] of integer;
  n, i, j, k, l, m, u, x : integer;
  c : array[1..100] of integer;
begin
  read(n, x);
  k := 0;
  m := 0;
  l := 0;
  u := 0;
  j := 0;
  i := 0;
  for i := 1 to n do begin
    read(c[i]);
    if c[i] > 0 then b[c[i]] := 1 else a[c[i]] := 1;
  end;
  if x < 0 then begin
    for i := x to -1 do begin
      if a[i] = 1 then begin
        u := 1;
        break;
      end;
    end;
    if i = 0 then begin
      j := 0;
      while (k>x) do begin
        dec(k);
      end;
      k := abs(k);
      while (b[j]<>1) and (abs(j)<1000) do begin
        inc(m);
        inc(j);
      end;
      m := m * 2 + k;
    end;
  end;
  if x > 0 then begin
    for i := 0 to x do begin
      if(b[i]) = 1 then begin
        u := 1;
        break;
      end;
    end;
    if i = x + 1 then begin
      j := 0;
      while m < x do begin
        inc(m);
      end;
      while (a[j]<>1) and (abs(j)<1000) do begin
        inc(k);
        dec(j);
      end;
      k := k * 2 + m;
    end;
  end;
  if u = 1 then writeln('Impossible') else begin
    write(m,' ',k);
  end;
  readln;readln;
end.
correct my solution but WA1 it's very bad ((( who knows test 1?

Edited by author 08.11.2009 14:04
Your code is very crazy :)
1. He get wrong answer for demo test
2.
if x < 0 then begin
    for i := x to -1 do begin (*)
      if a[i] = 1 then begin
        u := 1;
        break;
      end;
    end;
    if i = 0 then begin (**)
How do you think - it is possible to go get TRUE in condition (**) if cycle condition (**) is that?

And the same bug in

    for i := 0 to x do begin (*)
      if(b[i]) = 1 then begin
        u := 1;
        break;
      end;
    end;
    if i = x + 1 then begin (**)

More help only via e-mail.


Edited by author 08.11.2009 15:55
Re: WA 1
Posted by rodge(Vologda ML) 20 Jan 2010 22:13
Thank you )))
I am thinking and rewriting me programm for 10 minutes now )))
and got AC it's amazing )))