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

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

Firstly i came up with this solution: https://mirror.codeforces.com/contest/1542/submission/121218884 I think it's O(n) in worst cases, and i got TLE. But shouldn't O(n) be sufficient for these constraints?

After the contest I also updated a O(logn) solution, and its similar to others that i saw submitted, but its getting TLE too: https://mirror.codeforces.com/contest/1542/submission/121269280

What am I missing here?

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

»
5 лет назад, скрыть # |
 
Проголосовать: нравится +16 Проголосовать: не нравится

I didn't think much but Im certain that you should make p long long. Its possible for it to keep overflowing and doing a lot of interactions.

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

If $$$a$$$ is $$$10^9-1$$$ and $$$n$$$ is $$$10^9$$$,first $$$p$$$ will multipliy by $$$a$$$ and then $$$p$$$ is $$$10^9-1$$$,second $$$p$$$ will multiply by $$$a$$$ again and $$$p$$$ will be more than $$$\text{INT_MAX}$$$.It will be very likely that $$$p$$$ overflows and make it less than or equal to $$$n$$$,so this code will keep running and you will get TLE.