News for hackers. Stuff that matters.
Re:C++ basics for competitive programming by Nimitz14 on Friday March 04, 2016 @02:19PM (#11226188)
> proposes a vector of vectors to make a 2D matrix

what would be the right way to do this?

Re:C++ basics for competitive programming by Stasis5001 on Friday March 04, 2016 @03:04PM (#11226508)
2D arrays that are laid out as a linear array of mn elements are faster to iterate through. That's what happens when you declare e.g. int a[5][4], you get the same layout as int a[20]. A vector of vectors is fairly sprawling in memory, and generally matrices don't get resized so you want this compact form because it's quicker to loop through (either way is O(mn), but one has a way better coefficient).