I would say that no, it's not idiomatic C++. There's no reason to use dynamic allocation for your vector<bool>
, for one obvious example.
As for its being faster, yes, that's expected and fits well with previous testsprevious tests.
If you care about speed, you could at least consider using operator[]
instead of at
. I rarely find at
very useful, personally.
I'd advise against using std::endl
as a general rules. If you just want a new-line, just write a new-line. If you want a new-line followed by a flush (which is what endl
actually does) do that explicitly, such as std::cout << res << "\n" << std::flush;
.
While res
isn't exactly a terrible name, I think something more descriptive (e.g., result
) would be better. If (for whatever reason) you're concerned about the length of the name, I'd consider using sum
instead.