为甚 Wa 和 Runtime error??

Program p1417;
Var i,j,k,m,n:longint;
q,p:boolean;
a,f,t1:array[1..1000000] of longint;
t2:array[1..1000000] of 0..1;
d:array[1..40000] of longint;

Procedure inputbox;
begin
readln(n,m);
for i:=1 to n do
read(a[i]);
readln;
for i:=1 to m do
read(d[i]);
end;

Procedure work;
begin
fillchar(t2,sizeof(t2),0);
fillchar(f,sizeof(f),0);
j:=0;
q:=false; p:=true;
for i:=1 to n do
begin
if a[i]+i>n then
begin
f[i]:=1;
if not q then j:=i;
q:=true;
end else
if q then f[i]:=2 else p:=false;
end;
q:=false;
if not p then
for i:=j downto 1 do
begin
if a[i]+i>n then
k:=i else
begin
if a[i]+i>=k then f[i]:=2 else
f[i]:=1+f[i+a[i]];
end;
end;
end;

Procedure print;
begin
for i:=1 to m-1 do
write(f[d[i]],' ');
writeln(f[d[m]]);
end;

Begin
inputbox;
work;
print;
End.

2 条评论

  • @ 2013-09-19 19:18:35

    数组越界?

  • @ 2013-09-17 20:05:59

    只过前两数据
    最后三个运行时错误

  • 1

信息

ID
1471
难度
6
分类
动态规划 | 单调性DP 点击显示
标签
递交数
787
已通过
212
通过率
27%
被复制
2
上传者