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

Автор ishan_luhani, история, 9 месяцев назад, По-английски

Hello everyone, I am facing a problem with a Problem.

Problem Link: https://codeforces.com/problemset/problem/363/B

When I tried to submit my Python Code. It failed due to TLE, But when I converted it to CPP with help of a website. It was Accepted.

CPP Solution Link: https://codeforces.com/contest/363/submission/228253805

Is there a trick in python I am missing? or Is it that I should switch to CPP?

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

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

Auto comment: topic has been updated by ishan_luhani (previous revision, new revision, compare).

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

Yeah, it's pretty well known that C++ is much faster than Python. I'd suggest you switch, that way you prevent TLEs even if your algorithm is fast enough.

PS: you can solve this using prefix sums, this will probably prevent the TLE in python. Submission: https://codeforces.com/contest/363/submission/217607313

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

    Thanks, The Solution was accepted by using the prefix sum.

    I will be changing to cpp soon.