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 1362. Classmates 2

Optimization
Posted by Pavlik 30 Sep 2008 14:39
I accepted 0.39(5kb). I use template veckor class(C++) to store list of employees. But I don't know how make my program faster :(

Edited by author 30.09.2008 14:40
Re: Optimization
Posted by Pavlik 30 Sep 2008 14:47


Edited by author 30.09.2008 14:51
Re: Optimization
Don't use vectors - these are VERY slow structures (as, by the way, all STL components). Rewrite with usual arrays - and, I think, speed of your code will increase several times...
Re: Optimization
Posted by hoan 6 Dec 2010 23:01
i use vector too, i think if i got use array memory limit have exceeded.
Re: Optimization
Posted by Vlad 31 Mar 2011 19:45
Vedernikoff Sergey (HSE: EconomicsForever!) wrote 2 October 2008 00:46
Don't use vectors - these are VERY slow structures (as, by the way, all STL components). Rewrite with usual arrays - and, I think, speed of your code will increase several times...
This statement is just wrong.
Re: Optimization
In which part? For any STL component I can write much faster analog.
Re: Optimization
Posted by Vlad 2 Apr 2011 01:53
Well, I was refering only to vectors. Of course you can make sets/maps/other stuff faster.

But the underlying structure of a vector is the same array.
E.g. vector<int> is just a {array pointer, size, reserved mem}.

I've heard this myth about vectors being slow several times, that's exactly why I've done some real testing of it - absolutely no difference, especially if you give the size beforehand (which you have to do in case of arrays).
Actually, if you use an iterator to iterate through your vector, it can sometimes actually be faster for different reasons.

The only difference may come from using multidimensional (i.e. nested) vectors - in that case, indeed, there can be some performance differences, but still, saying "VERY slow structures" is an extreme exaggeration... remember, you said "increase several times" :).


Edited by author 02.04.2011 02:12
Re: Optimization
Posted by pmartynov 19 Apr 2015 22:03
vector<bool> is slow.