Skip to content

Instantly share code, notes, and snippets.

@tarawa
Created July 4, 2013 06:20
Show Gist options
  • Save tarawa/5925303 to your computer and use it in GitHub Desktop.
Save tarawa/5925303 to your computer and use it in GitHub Desktop.
ZOJ2767 (Pascal)
var
n,t,m,i,ans:longint;
f:array ['0'..'9'] of boolean;
ch:char;
g:boolean;
procedure test(p:longint);
var
s:string;
t:boolean;
begin
str(p,s);
g:=true;
for i:=1 to length(s) do
if f[s[i]] then
begin
t:=false;
break;
end;
if not t then exit;
if length(s)+m-p+1>ans then g:=false else ans:=length(s)+m-p+1;
end;
begin
while not eof do
begin
readln(n);
fillchar(f,sizeof(f),false);
for i:=1 to n do
begin
readln(ch);
f[ch]:=true;
end;
readln(t,m);
ans:=abs(m-t);
for i:=0 to 1000000 do
begin
test(m-i);
test(m+i);
end;
writeln(ans);
end;
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment