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

Автор toTalmeSS, история, 8 лет назад, По-английски

Hello... I got TLE on the following problem. I myself found out that it's taking an awful amount of time for inputs with eight or nine digits! How can I optimize my code and reduce the complexity? I tried to devise a formula, but couldn't go anywhere. I can still try if any of you could tell me how to approach...

Thanks in advance.

Problem link My code

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

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

You need to find a formula to solve this problem, you can't iterate over 109 elements.

  • Actually, one simple observation is enough to solve the problem: For every number x that has a negative sign, the will be a number x + M with a positive sign. There are N / 2 total positive numbers, so the answer is simply .
C++ Code