比赛 20121106 评测结果 WWAWWWWW
题目名称 过河 最终得分 12
用户昵称 Abel·S 运行时间 0.659 s
代码语言 Pascal 内存使用 38.35 MiB
提交时间 2012-11-06 11:30:34
显示代码纯文本
program cojs_p1251;
var
	f,p:array[0..20000,0..1000] of boolean;
	i,j,k,l,m,n,t:longint;
procedure ass;
begin
	assign(input,'rivera.in');
	assign(output,'rivera.out');
	reset(input);
	rewrite(output);
end;
procedure cls;
begin
	close(input);
	close(output);
end;
procedure init;
var
	i,j,k,t:longint;
	a,b:array[0..1000] of longint;
begin	
	ass;
	readln(n);
	for i:=1 to n do
		readln(a[i],b[i]);
	for t:=1 to 20000 do
		for i:=1 to n do
		begin
			if t mod (a[i]+b[i])>a[i]
				then p[t,i]:=false
				else p[t,i]:=true;
                end;
	for i:=1 to 20000 do
	begin
		p[i,n+1]:=true;
		p[i,0]:=true;
	end;
	fillchar(f,sizeof(f),false);
end;
begin
	init;
	f[1,0]:=true;
	for t:=2 to 20000 do
		for i:=0 to n do
		begin
			if f[t-1,i]
			then  begin
				if i-5<=0 then
				for j:=0 to i+5 do
					if p[t,j] then f[t,j]:=true;
				if (i-5>0) and (i+5<=n+1) then
				for j:=i-5 to i+5 do
					if p[t,j] then f[t,j]:=true;
				if i+5>n+1
					then begin writeln(t); cls; halt; end;
				f[t,i]:=true;
                        end;
		end;
	writeln('NO');
	cls;
end.