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 1124. Mosaic

Why I get WA? Pelase, help me!!!!!!! (+)
Posted by Nazarov Denis (nsc2001@rambler.ru) 12 Jan 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. (+)
Posted by shitty.Mishka 12 Jan 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(+)
Posted by Nazarov Denis (nsc2001@rambler.ru) 13 Jan 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 (+)
Posted by shitty.Mishka 13 Jan 2002 18:11
2 1
1
2

The answer is 0.

Good luck!
Re:Still WA(+) Pleae help me!
Posted by Nazarov Denis (nsc2001@rambler.ru) 13 Jan 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!
Posted by Yashar Abbasov 22 Dec 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?