Блог пользователя kazuya

Автор kazuya, история, 4 года назад, По-английски

I was solving this problem 1202B - You Are Given a Decimal String... and I got some idea about it but the time complexity for my algorithm was O(10^8) and since time limit mentioned was 2 sec I didn't implement it and decided to look at the editorial, in which author mentioned this : But, it will work only in C++, since the language is fast and 2⋅10^8 basic operations are executed in less than 0.5 seconds. Can someone explain this? (as far as I know up to 10^6 operations can be done in 1 second, so for 2 seconds ~ 2*10^6, right ?).

  • Проголосовать: нравится
  • +17
  • Проголосовать: не нравится

»
4 года назад, # |
  Проголосовать: нравится +24 Проголосовать: не нравится

I don't know that there is much to explain... You can do closer to $$$2*10^8$$$ operations per second in C++ if those operations are low-level operations (array accesses, additions, bitshifts, multiplies, subtractions, xors, et cetera). Mods and divisions are slightly slower. If you are doing things like hashmap lookups, reading input, or printing output, you can do about $$$10^6$$$ of those per second. If you use Java, the cut-off is maybe 70% what it is in C++, since a lot of things have more overhead, but of course it really depends on what the operations are; sometimes it is closer to 30% of what C++ can do.

»
4 года назад, # |
  Проголосовать: нравится +12 Проголосовать: не нравится

It completely depends on the type of operations that you are going to use. For example (%) module operation takes much more time than (+) sum operation. If your operations are simple (like + and ×. But not / and %) C++ can do even more than 1e9 operations per second. The second thing that matters is your memory usage. If CPU can store all of the data in cash memory then your code will run way faster than the case that CPU should use RAM!

»
7 месяцев назад, # |
Rev. 3   Проголосовать: нравится 0 Проголосовать: не нравится

Is 1,5 seconds enough for O(10^10) in c++?

SecondThread