Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var a:array [1..1000,1..1000] of integer;
- solution:array [1..1000,1..1000] of boolean;
- m,n,i,j,tmp:longint;
- function finished:boolean;
- var i,j : longint;
- begin
- finished:= true;
- for i:= 1 to m do
- for j:= 1 to n do
- if a[i,j] = 1 then
- begin
- finished := false;
- exit;
- end;
- end; { finished }
- procedure change(x,y : longint);
- var i,j : longint;
- begin
- solution[x,y]:= not solution[x,y];
- for i:= y downto 1 do
- if a[x,i] = 2 then break
- else if (i <> y) then a[x,i] := integer(not(a[x,i]=1));
- for i:= y to n do
- if a[x,i] = 2 then break
- else if (i <> y) then a[x,i] := integer(not(a[x,i]=1));
- for i:= x downto 1 do
- if a[i,y] = 2 then break
- else if (i <> x) then a[i,y] := integer(not(a[i,y]=1));
- for i:= x to m do
- if a[i,y] = 2 then break
- else if (i <> x) then a[i,y] := integer(not(a[i,y]=1));
- a[x,y]:=integer(not(a[x,y]=1));
- end; { change }
- procedure solve (x,y : longint);
- var i,j : longint;
- begin
- for i:=x to m do
- for j:= y to n do
- if not finished then
- begin
- begin
- if not(a[i,j] = 2) then change(i,j);
- if finished then exit;
- if j = n then solve(i+1,1)
- else solve(i,j+1);
- if finished then exit;
- if not(a[i,j] = 2) then change(i,j);
- end;
- end;
- end; { solve }
- begin
- readln(m,n);
- for i:= 1 to m do
- begin
- for j:= 1 to n do
- begin
- read(a[i,j]);
- solution[i,j]:= false;
- end;
- end;
- solve(1,1);
- for i:= 1 to m do
- for j:= 1 to n do
- write(integer(solution[i,j]));
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement