ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1269. Obscene Words Filter

Why TLE on test 7?
Posted by ilya_romanenko 3 Jun 2011 23:39
I can't find mistakes. Please help!
var
m:array[1..10000]of string;
m1:string;
a,b,c,d,i,j,k:integer;
begin
readln(a);
for i:=1 to a do
readln(m[i]);
readln(b);
for i:=1 to b do
begin
c:=0;
d:=100000000;
readln(m1);
for j:=1 to a do
if((pos(m[j],m1)>0)) then
begin
c:=pos(m[j],m1);
if(c<d)then d:=c;
end;
if(d<>100000000)then begin
writeln(i,' ',d);
exit;
end;
end;
writeln('Passed');
end.
Re: Why TLE on test 7?
Posted by AterLux 4 Jun 2011 01:20
Your program correct, but algorithm you chosen is too slow.

You trying to compare 10000 words with up to 300000 lines (is every line contains one symbol with CR LF - total 900KB). Also Pos function have very simple realization and it can take up to n*m comparations (for example if haystack and needle both have same repeating simbol except last one)

to solve this problem read this: http://ru.wikipedia.org/wiki/%D0%90%D0%BB%D0%B3%D0%BE%D1%80%D0%B8%D1%82%D0%BC_%D0%90%D1%85%D0%BE_%E2%80%94_%D0%9A%D0%BE%D1%80%D0%B0%D1%81%D0%B8%D0%BA

out of this problem for education, hov to speed up string comparation read this: http://ru.wikipedia.org/wiki/%D0%90%D0%BB%D0%B3%D0%BE%D1%80%D0%B8%D1%82%D0%BC_%D0%9A%D0%BD%D1%83%D1%82%D0%B0_%E2%80%94_%D0%9C%D0%BE%D1%80%D1%80%D0%B8%D1%81%D0%B0_%E2%80%94_%D0%9F%D1%80%D0%B0%D1%82%D1%82%D0%B0  you can use it to solve problem 1423 (but that problem can be solved using another methods)
Re: Why TLE on test 7?
Posted by ilya_romanenko 22 Jun 2011 17:00
I can't understand! I use algorithm Aho-Korasic,but I have TLE on test7! Why? Can anybody send correct algorithm Aho-Korasic?
P.S. Sorry for bad English.

Edited by author 23.06.2011 16:27

Edited by author 29.06.2011 18:27
Re: Why TLE on test 7?
Posted by Juliet 27 Jun 2011 14:46
Apply the GOOD JOB for College ACMers to Make Large Money and Become a Millionaire

Hello, We need large no. of dedicated and hard working ACMers. The payment is good so we need ACMers to be efficient. All you have to do to get the job is to sign up at our websites. The link of our websites are given below.

http://www.PaisaLive.com/register.asp?3556638-4847933

After the registration, a confirmation email will be sent to your specified email address. Please click on the link inside the confirmation email to activate your account and recieve ACM work instantly. For any other queries you can mail the administrator.

Miss Juliet

Admin paisalive.com