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

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

Why I get WA? Pelase, help me!!!!!!! (+)
Послано Nazarov Denis (nsc2001@rambler.ru) 12 янв 2002 21:16
My program:

Program t1124;

Var M,N,i,j,k,a,t  :integer;
    c,s,u          :array[1..500]of integer;

begin
a:=0;
for i:=1 to 500 do c[i]:=i;
for i:=1 to 500 do s[i]:=0;
for i:=1 to 500 do u[i]:=-1;
read(m,n);
for i:=1 to m do
 for j:=1 to n do begin
  read(k);
  if k<>i then begin
   a:=a+1;
   s[k]:=s[k]+1;
   for t:=1 to m do
    if c[t]=k then
     c[t]:=i;
  end;
 end;
t:=0;
for i:=1 to m do if s[i]>0 then begin
 if u[c[i]]=-1 then u[c[i]]:=0;
 if s[i] mod 2=1 then u[c[i]]:=u[c[i]]+1;
end;
for i:=1 to m do
 if u[i]<>-1 then
  if (u[i]=0)or(u[i]=2) then t:=t+1 else t:=t+(u[i] div 2);
if t>0 then t:=t-1;
writeln(a+t);
end.
A test for you. (+)
Послано shitty.Mishka 12 янв 2002 23:02
3 3
1 2 2
2 3 3
3 1 1
The answer should be 6, not 7.

Good luck.
Re: Still WA(+)
Послано Nazarov Denis (nsc2001@rambler.ru) 13 янв 2002 09:53
> 3 3
> 1 2 2
> 2 3 3
> 3 1 1
> The answer should be 6, not 7.
>
> Good luck.
My new program:
Program t1124;

Var M,N,i,j,k,a,t  :integer;
    c,s,u          :array[1..500]of integer;

begin
a:=0;
for i:=1 to 500 do c[i]:=i;
for i:=1 to 500 do s[i]:=0;
for i:=1 to 500 do u[i]:=-1;
read(m,n);
for i:=1 to m do
 for j:=1 to n do begin
  read(k);
  if k<>i then begin
   a:=a+1;
   s[k]:=s[k]+1;
   for t:=1 to m do
    if c[t]=c[k] then
     c[t]:=c[i];
  end;
 end;
t:=0;
{for i:=1 to m do if s[i]>0 then begin
 if u[c[i]]=-1 then u[c[i]]:=0;
 if s[i] mod 2=1 then u[c[i]]:=u[c[i]]+1;
end;
for i:=1 to m do
 if u[i]<>-1 then
  if (u[i]=0)or(u[i]=2) then t:=t+1 else t:=t+(u[i] div 2);}
for i:=1 to m do begin
  if c[i]<>0 then t:=t+1;
  for j:=i+1 to m do
   if c[j]=c[i] then
    c[j]:=0;
 end;
if t>0 then t:=t-1;
writeln(a+t);
end.
Another test for you (+)
Послано shitty.Mishka 13 янв 2002 18:11
2 1
1
2

The answer is 0.

Good luck!
Re:Still WA(+) Pleae help me!
Послано Nazarov Denis (nsc2001@rambler.ru) 13 янв 2002 21:49
Thank for you help!But I still get WA!.I don't know what's wrong.
I have 2 programs. But they both wrong!!!. Please, help me!!!
May be my algorithm is wrong??!
\\\\\\\Program I:

Program t1124;

Var M,N,i,j,k,a,t  :integer;
    c,s,u          :array[1..500]of integer;

begin
a:=0;
for i:=1 to 500 do c[i]:=i;
for i:=1 to 500 do s[i]:=0;
for i:=1 to 500 do u[i]:=-1;
read(m,n);
for i:=1 to m do
 for j:=1 to n do begin
  read(k);
  if k<>i then begin
   a:=a+1;
   s[k]:=s[k]+1;
   for t:=1 to m do
    if c[t]=c[k] then
     c[t]:=c[i];
  end;
 end;
t:=0;
for i:=1 to m do if s[i]>0 then begin
 if u[c[i]]=-1 then u[c[i]]:=0;
 if s[i] mod 2=1 then u[c[i]]:=u[c[i]]+1;
end;
for i:=1 to m do begin
  if (c[i]<>0)and(s[i]<>0) then t:=t+1;
  for j:=i+1 to m do
   if c[j]=c[i] then
    c[j]:=0;
 end;
if t>0 then t:=t-1;
writeln(a+t);
end.
\\\\\\\\Program II:

Program t1124;

Var M,N,i,j,k,a,t  :integer;
    c,s,u          :array[1..500]of integer;

begin
a:=0;
for i:=1 to 500 do c[i]:=i;
for i:=1 to 500 do s[i]:=0;
for i:=1 to 500 do u[i]:=-1;
read(m,n);
for i:=1 to m do
 for j:=1 to n do begin
  read(k);
  if k<>i then begin
   a:=a+1;
   s[k]:=s[k]+1;
   for t:=1 to m do
    if c[t]=c[k] then
     c[t]:=c[i];
  end;
 end;
t:=0;
for i:=1 to m do if s[i]>0 then begin
 if u[c[i]]=-1 then u[c[i]]:=0;
 if s[i] mod 2=1 then u[c[i]]:=u[c[i]]+1;
end;
for i:=1 to m do
 if u[i]<>-1 then
  if (u[i]=0)or(u[i]=2) then t:=t+1 else t:=t+(u[i] div 2);
if t>0 then t:=t-1;
writeln(a+t);
end.
Re: Re:Still WA(+) Pleae help me!
Послано Yashar Abbasov 22 дек 2007 16:44
My method is similar with yours. I have WA#13. my prog passed all tests that i had.I can't find my mistake. can anyone give me some tricky tests for this problem?