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

Автор aastik231205, история, 6 часов назад, По-английски

Hello guys, I just realised how much of a difference putting const in a global variable can make. I was doing CSES problem Coin combinations II. I was getting tle on the problem for quite a while. Just for trying i changed the global mod value's datatype from long long to const long long. My code which was giving tle on 1s got executed in 0.2s due to that 1 change.

Here's my Old submission and here's the New one.

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

»
5 часов назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

how does that work ?

  • »
    »
    3 часа назад, # ^ |
      Проголосовать: нравится +18 Проголосовать: не нравится

    Integer division is an extremely slow operation. However, if the divisor is a constant, the compiler can optimize it by changing the operation into several non-division operations and it can significantly boost the execution speed.

    • »
      »
      »
      3 часа назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      djm03178 Can you please share some reference regarding it if you can find one?

      • »
        »
        »
        »
        2 часа назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится
    • »
      »
      »
      116 минут назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      Something new to add up in my arsenal