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 1542. Autocompletion

Dima&Dima Other ways of solution [9] // Problem 1542. Autocompletion 21 Apr 2007 18:05
Hallo all!
I think here is only one solution for this problem.
First of all  sort incoming data in alphabetical order. Then choose words in second array. sort it by frequenscy. Take first  10 words and print them. And do not forget to sort word's with same frequency alphabeticaly. That's All.
But when I implement whis algoritm it slove my test, slove test coming with problem, nevertheles it cannot pass first test at server.

Can U advise me some other ways how to slow this problem.
lbvf(dog)mail(point)ru

All the Best to U...
Mingfei Li Re: Other ways of solution [8] // Problem 1542. Autocompletion 21 Apr 2007 19:32
My algorithms is the same, but TLE on test 12
Molochiy Ivan[ Lviv NU ] Re: Other ways of solution [7] // Problem 1542. Autocompletion 21 Apr 2007 20:17
Maybe a main problem in sorting? I had WA 12
Mace(Lviv Polytechniс NU) Re: Other ways of solution [5] // Problem 1542. Autocompletion 21 Apr 2007 22:39
Hash codes of strings and qsort can help to increase speed of sorting, I think. I got TLE12, and don`t have a time during contest to rewrite my program. Maybe later I`ll try to solve it again.
Dima&Dima Re: Other ways of solution [2] // Problem 1542. Autocompletion 22 Apr 2007 12:31
What kind of Hash codes did U use?
Todor Tsonkov Re: Other ways of solution [1] // Problem 1542. Autocompletion 22 Apr 2007 14:13
I think your output file has one more empty line, when I had such code I had WA1, now I'm one of the many TL12- ers :(
Denis Koshman Re: Other ways of solution // Problem 1542. Autocompletion 15 Jul 2008 00:37
I built characters tree for request and almost beaten the top with it ))
KALO Re: Other ways of solution [1] // Problem 1542. Autocompletion 11 Feb 2011 03:51
Mace(Lviv Polytechniс NU) wrote 21 April 2007 22:39
Hash codes of strings and qsort can help to increase speed of sorting

Really good hint! Thanks!
Лукьянчиков Владимир Игоревич Re: Other ways of solution // Problem 1542. Autocompletion 11 Feb 2011 08:29
Also this problem can be solved with segment tree and some preprocessing:

1) create array of pairs <string word,int frequency> and sort this array

2) build segment tree on maximum on frequences of sorted array

3) answering the query:
find all words which matches the pattern - these words will be in one sequental interval because array sorted lexocographically,here example of finding this interval:
L = lower_bound(array,array+n,make_pair(pattern,-INF))-array; //substraction pointers
R = upper_bound(*,*,make_pair(pattern+"zzzzz_fill_until_max_len",+INF))-array;
now we found all relevant words, let's choose 10 most frequent:
1 most frequent word - find_max_with_segment_tree(L,R) - also should return index of maximal element
Now you should change maximal element to -INF in order to provide that second most frequent word will be founded by segment tree; change second to -INF and so on;
after answering 10 questions just undo changes: you know old values and indices of altered elements, use this this information and restore segment tree.


Edited by author 11.02.2011 08:31
Dima&Dima Re: Other ways of solution // Problem 1542. Autocompletion 22 Apr 2007 12:29
I was using qsort. And testing how it sorts simple incoming data by the  debuger, it was testing normaly. It's looks pretty mistical... I can belive in TLE, but WA in first test looks very strange.

To find a problem at my code I want to create testing porgram that counts words in big Engish book. And then test A program on created test data.