var a:array[0..501,0..501]of longint; v:array[0..501]of boolean; vv:array[0..501,0..501]of boolean; l,r:array[1..500]of integer; n,i,j,k,m,ans,sum:longint; procedure bianli(i,j:integer); begin vv[i,j]:=false; if i=n then begin v[j]:=true; if j<l[k] then l[k]:=j;if j>r[k] then r[k]:=j;end; if (a[i,j]>a[i,j-1])and(vv[i,j-1]) then bianli(i,j-1); if (a[i,j]>a[i,j+1])and(vv[i,j+1]) then bianli(i,j+1); if (a[i,j]>a[i+1,j])and(vv[i+1,j]) then bianli(i+1,j); if (a[i,j]>a[i-1,j])and(vv[i-1,j]) then bianli(i-1,j); end; begin read(n,m); for i:=1 to m do l[i]:=m+1; for i:=1 to n do for j:=1 to m do read(a[i,j]); for k:=1 to m do if (a[1,k]>=a[1,k-1])and(a[1,k]>=a[1,k+1]) then begin for i:=1 to n do for j:=1 to m do vv[i,j]:=true; bianli(1,k); end; for i:=1 to m do if not(v[i]) then inc(sum); if sum>0 then begin writeln('0');writeln(sum);halt;end; i:=1;k:=0; while i<=m do begin for j:=1 to m do if(l[j]<=i)and(r[j]>k) then k:=r[j]; i:=k+1; inc(sum); end; writeln('1'); writeln(sum); end. /************************************************************** Problem: 2299 User: admin Language: Pascal Result: Wrong Answer ****************************************************************/