Page 1 of 2

11855 - Buzzwords

Posted: Mon Oct 04, 2010 5:08 am
by Angeh
why is the First Input
5
4
4
2
2

???

Edit :
GOT AC ... in 0.9
The Test Cases Are Wrong ...
But How to get AC in Less Time ... ???
I Used Trie !! counted the max of each Level .... 26 * N(N-1)/2
is There Any other solution ?????

Re: 11855 - Buzzwords

Posted: Mon Oct 04, 2010 10:45 am
by Igor9669
I use hash in my solution!

Re: 11855 - Buzzwords

Posted: Mon Oct 04, 2010 12:59 pm
by Angeh
Hi ,Igor ...
0.536 is Good Time
do you hash all n(n-1)/2 strings ?
Then How do you Hash them whats your Function for hashig ... ?

Re: 11855 - Buzzwords

Posted: Mon Oct 04, 2010 1:27 pm
by Igor9669
Yes!

Code: Select all

long long getHash(string s)
{
const int p = 31;
long long hash = 0, p_pow = 1;
for (int i=0; i<s.length(); ++i)
{
	hash += (s[i] - 'a' + 1) * p_pow;
	p_pow *= p;
}
return hash;
}

Re: 11855 - Buzzwords

Posted: Mon Oct 04, 2010 1:36 pm
by Angeh
wouldn't long long overflow for strings of size = 999 ?
31^999 ??
Does your Code Work for Case:
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
?

Re: 11855 - Buzzwords

Posted: Mon Oct 04, 2010 2:36 pm
by Igor9669
Of cousre it will,but this is not a problem it works like you get it by module!

Re: 11855 - Buzzwords

Posted: Mon Oct 04, 2010 2:41 pm
by Angeh
I have Got AC this Problem ...
so would you please send me your code
angeh.a2@gmail.com
i Just want to learn more from your code implementation

Re: 11855 - Buzzwords

Posted: Mon Oct 04, 2010 2:44 pm
by Igor9669
Sorry,but I don't save the codes of Ac problems in my computer((

Re: 11855 - Buzzwords

Posted: Mon Oct 04, 2010 2:52 pm
by Igor9669
But I could explain my idea here if you want???

Re: 11855 - Buzzwords

Posted: Mon Oct 04, 2010 3:12 pm
by Angeh
ok no problem ...
i have Tried what you said ...
but i Get Runtime Error ...
is your Code Somthing like this .... ?

Code: Select all

maxes[ k ] is the most repete of string lenght k ...
        map<long long ,int> MAP;
        long long P=31;
        FOR(i,n){
            long long Hash=0,Pow=1;
            for(int j=i;j<n;++i){
                Hash += (line[j]-'A'+1)*Pow;
                MAP[Hash]++;
                maxes[j-i]<MAP[Hash] ? maxes[j-i]=MAP[Hash] :0 ;
                Pow*=P;                
            }
        }
printf out put .... 

Re: 11855 - Buzzwords

Posted: Mon Oct 04, 2010 3:14 pm
by Igor9669
Yes,it was something likes yours!
try to increase the size of array m!

Re: 11855 - Buzzwords

Posted: Mon Oct 04, 2010 3:22 pm
by Angeh
Igor9669 wrote:Yes,it was something likes yours!
try to increase the size of array m!
Array m ?????
do you use STL map to save the Hashes ?

Re: 11855 - Buzzwords

Posted: Mon Oct 04, 2010 3:24 pm
by Igor9669
sorry,maxes I mean!
No I don't use map!

Re: 11855 - Buzzwords

Posted: Mon Oct 04, 2010 3:27 pm
by Angeh
thanks for your help and sorry for this much Question ...
but if you dont use map , how do save the Hashes ???
i'm confused :(

Re: 11855 - Buzzwords

Posted: Mon Oct 04, 2010 3:29 pm
by Igor9669
)) map is also a good choice, but I use an array with type of pair<long long,int>!