比赛 |
20121106 |
评测结果 |
AAAAAAAA |
题目名称 |
过河 |
最终得分 |
100 |
用户昵称 |
Vow Ryan |
运行时间 |
0.084 s |
代码语言 |
Pascal |
内存使用 |
1.84 MiB |
提交时间 |
2012-11-06 11:49:28 |
显示代码纯文本
var
a,b:array[0..1010]of longint;
f:array[0..2000,0..1010]of boolean;
i,j,k,l,m,n,time,p:longint;
function min(a,b:longint):longint;
begin
if a<b then exit(a) else exit(b);
end;
function max(a,b:longint):longint;
begin
if a>b then exit(a) else exit(b);
end;
begin
assign(input,'rivera.in');reset(input);
assign(output,'rivera.out');rewrite(output);
read(n);
fillchar(a,sizeof(a),1);
for i:=1 to n do read(a[i],b[i]);
fillchar(f,sizeof(f),false);
f[0,0]:=true;
p:=0;
while true do
begin
inc(p);
// writeln(p);
for i:=0 to n+5 do
if (p mod (a[i]+b[i])>0)and(p mod (a[i]+b[i])<=a[i]) then
begin
f[p,i]:=false;
for j:=max(0,i-5) to min(n+1,i+5) do
if ((p-1) mod (a[j]+b[j])>0)and((p-1) mod (a[j]+b[j])<=a[j]) or (p-1=0) then
begin
f[p,i]:=f[p,i] or f[p-1,j];
if i>=n+1 then
if f[p,i] then
begin
writeln(p);
close(input);close(output);
halt;
end;
if f[p,i] then break;
end;
end;
if p>1000 then break;
end;
writeln('NO');
close(input);close(output);
end.