I've heard find() works faster then [], also make sure to call clear() between testcases.
Try to post your code here - Larry might tell you if he did something in different way.
I don't know, I use printf instead of cout, but otherwise, everything looks the same..
I use .clear() instead of reallocating the memory.. don't know which is faster..
[] is different from .find in that if the key is not in the map, it'll create it, while in .find, it'll just return 0. In this case, since that's what we want to do anyhow, I used []..
Larry wrote:I don't know, I use printf instead of cout, but otherwise, everything looks the same..
I use .clear() instead of reallocating the memory.. don't know which is faster..
[] is different from .find in that if the key is not in the map, it'll create it, while in .find, it'll just return 0. In this case, since that's what we want to do anyhow, I used []..
Larry, can you send me your code to have a look at the differences?
Your last code results in WA because it always prints 0.0000. (at least for me)
cout is fast enough for this problem: I've just moved to second place with 0.8sec, still using cout for output...
minskcity wrote:Your last code results in WA because it always prints 0.0000. (at least for me)
cout is fast enough for this problem: I've just moved to second place with 0.8sec, still using cout for output...
So you use your own hash fucntion?
I don't know why there is some problem with STL hash_map with const char*
cytmike wrote:
So you use your own hash fucntion?
I don't know why there is some problem with STL hash_map with const char*
I guess hash_map is actually using pointer to char, not array of chars as a key (It's definetely true for set, I checked it). You should try to use string.
BTW, hash I'm using is very easy to implement: I'm using a tree, each node has an array of 256 pointers to the next node(for each char) and a counter. Even the most naive implementation runs in under 2sec. My basic hash implementation was ~20 lines long and was coded in 10 minutes. Later I managed to optimize it to run in under 0.5sec, which moved me to 1st place. (but you have to work on input/output if you want to achieve that time)
cytmike wrote:
So you use your own hash fucntion?
I don't know why there is some problem with STL hash_map with const char*
I guess hash_map is actually using pointer to char, not array of chars as a key (It's definetely true for set, I checked it). You should try to use string.
BTW, hash I'm using is very easy to implement: I'm using a tree, each node has an array of 256 pointers to the next node(for each char) and a counter. Even the most naive implementation runs in under 2sec. My basic hash implementation was ~20 lines long and was coded in 10 minutes. Later I managed to optimize it to run in under 0.5sec, which moved me to 1st place. (but you have to work on input/output if you want to achieve that time)
cytmike wrote:
So you use your own hash fucntion?
I don't know why there is some problem with STL hash_map with const char*
I guess hash_map is actually using pointer to char, not array of chars as a key (It's definetely true for set, I checked it). You should try to use string.
BTW, hash I'm using is very easy to implement: I'm using a tree, each node has an array of 256 pointers to the next node(for each char) and a counter. Even the most naive implementation runs in under 2sec. My basic hash implementation was ~20 lines long and was coded in 10 minutes. Later I managed to optimize it to run in under 0.5sec, which moved me to 1st place. (but you have to work on input/output if you want to achieve that time)
but hash_map doesn't support string (or i just can't use it like using string in map)