ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1124. Мозаика

why I got TL!!!!!!!!!!!!
Послано ACer 15 авг 2003 08:32
var  l,m,n,i,j,t,total,s:longint;
     closed,open,now:longint;

     a:array[0..500,0..500] of integer;
     b:array[1..500]of boolean;

function done(d,p:longint):boolean;
var k:longint;
begin
     done:=false;
     for k:=1 to a[d,0] do
         if a[d,k]=p then exit;
     done:=true;
end;
begin
     read(m);
     read(n);
     for i:=1 to m do
         for j:=1 to n do begin
         read(t);
         if t<>i then begin
            if done(i,t) then
            begin
               inc(a[i,0]);
               a[i,a[i,0]]:=t;
               b[i]:=true;
               end;
            inc(s);
            end;
         end;
     for i:=1 to m do
         if b[i] then begin
            closed:=a[i,0];
            open:=0;
            while open<closed do begin
            now:=0;
                  for j:=open+1 to closed do
                      for l:=1 to a[a[i,j],0] do
                      if done(i,a[a[i,j],l]) then begin
                      a[i,closed+now+1]:=a[a[i,j],l] ;
                      inc(now);
                      end;
                  open:=closed;
                  closed:=closed+now;
                  a[i,0]:=closed;
                  end;

            inc(total);
            for j:=1 to a[i,0] do b[a[i,j]]:=false;
            end;
     if total=0 then writeln(0)
                else writeln(s+total-1);
     end.
Re: why I got TL!!!!!!!!!!!!
Послано ACer 15 авг 2003 09:16
> var  l,m,n,i,j,t,total,s:longint;
>      closed,open,now:longint;
>
>      a:array[0..500,0..500] of integer;
>      b:array[1..500]of boolean;
>
> function done(d,p:longint):boolean;
> var k:longint;
> begin
>      done:=false;
>      for k:=1 to a[d,0] do
>          if a[d,k]=p then exit;
>      done:=true;
> end;
> begin
>      read(m);
>      read(n);
>      for i:=1 to m do
>          for j:=1 to n do begin
>          read(t);
>          if t<>i then begin
>             if done(i,t) then
>             begin
>                inc(a[i,0]);
>                a[i,a[i,0]]:=t;
>                b[i]:=true;
>                end;
>             inc(s);
>             end;
>          end;
>      for i:=1 to m do
>          if b[i] then begin
>             closed:=a[i,0];
>             open:=0;
>             while open<closed do begin
>             now:=0;
>                   for j:=open+1 to closed do
>                       for l:=1 to a[a[i,j],0] do
>                       if done(i,a[a[i,j],l]) then begin
>                       a[i,closed+now+1]:=a[a[i,j],l] ;
>                       inc(now);
>                       end;
>                   open:=closed;
>                   closed:=closed+now;
>                   a[i,0]:=closed;
>                   end;
>
>             inc(total);
>             for j:=1 to a[i,0] do b[a[i,j]]:=false;
>             end;
>      if total=0 then writeln(0)
>                 else writeln(s+total-1);
>      end.
Re: who can help me please
Послано ACer 15 авг 2003 09:17
> > var  l,m,n,i,j,t,total,s:longint;
> >      closed,open,now:longint;
> >
> >      a:array[0..500,0..500] of integer;
> >      b:array[1..500]of boolean;
> >
> > function done(d,p:longint):boolean;
> > var k:longint;
> > begin
> >      done:=false;
> >      for k:=1 to a[d,0] do
> >          if a[d,k]=p then exit;
> >      done:=true;
> > end;
> > begin
> >      read(m);
> >      read(n);
> >      for i:=1 to m do
> >          for j:=1 to n do begin
> >          read(t);
> >          if t<>i then begin
> >             if done(i,t) then
> >             begin
> >                inc(a[i,0]);
> >                a[i,a[i,0]]:=t;
> >                b[i]:=true;
> >                end;
> >             inc(s);
> >             end;
> >          end;
> >      for i:=1 to m do
> >          if b[i] then begin
> >             closed:=a[i,0];
> >             open:=0;
> >             while open<closed do begin
> >             now:=0;
> >                   for j:=open+1 to closed do
> >                       for l:=1 to a[a[i,j],0] do
> >                       if done(i,a[a[i,j],l]) then begin
> >                       a[i,closed+now+1]:=a[a[i,j],l] ;
> >                       inc(now);
> >                       end;
> >                   open:=closed;
> >                   closed:=closed+now;
> >                   a[i,0]:=closed;
> >                   end;
> >
> >             inc(total);
> >             for j:=1 to a[i,0] do b[a[i,j]]:=false;
> >             end;
> >      if total=0 then writeln(0)
> >                 else writeln(s+total-1);
> >      end.