- 奶牛排队
- 2009-06-12 19:50:29 @
编译通过...
├ 测试数据 01:答案正确... 0ms
├ 测试数据 02:答案正确... 0ms
├ 测试数据 03:答案正确... 0ms
├ 测试数据 04:答案正确... 0ms
├ 测试数据 05:答案正确... 0ms
├ 测试数据 06:答案正确... 0ms
├ 测试数据 07:答案正确... 0ms
├ 测试数据 08:答案正确... 9ms
├ 测试数据 09:运行超时...
├ 测试数据 10:运行超时...
---|---|---|---|---|---|---|---|-
Unaccepted 有效得分:80 有效耗时:9ms
type
maandmi=record
max,min:longint;
end;
var
n,b,c:longint;
s,i,j:longint;maxl:longint;
a:array[1..100000] of longint;
procedure init;
begin
readln(n);
for i:= 1 to n do
readln(a[i]);
end;
function findminandmax(i,j:longint):maandmi;
var
k,min1,max1:longint;
begin
min1:=maxlongint;max1:=0;
for k:= i to j do
begin
if a[k]max1 then begin max1:=a[k];findminandmax.max:=k;end;
end;
end;
procedure find(i,j:longint);
var
b,c:longint;
begin
if j-i>=1 then
begin
b:=findminandmax(i,j).min;
c:=findminandmax(i,j).max;
if (bi)and (bj) then begin find(i,b-1);find(b,j);end;
if b=i then find(i+1,j);
if b=j then find(i,j-1);
s:=c-b+1;
if s>maxl then maxl:=s;
end;
end;
begin
init;
s:=0;maxl:=0;
find(1,n);
writeln(maxl);
end.
1 条评论
-
hitman47 LV 8 @ 2009-09-18 11:33:07
memory
maybe you can set an array to remember all the min-digit and the max-digit instead of search them again and again.
- 1