We're looking at roughly 10^6 heap operations in 100 test cases, which is
around 10^8 heap operations total. I'd expect that to run in 4 minutes or
less in C++ no problem, but in Python I wouldn't be so confident. How long
does it run for?

On Wed, Aug 22, 2018 at 5:36 PM Eugene Yarmash <e.yarm...@gmail.com> wrote:

> Hello. I've tried to solve the problem using Python's heapq module, but
> that gave me 'Time limit exceeded' for the 2nd test case. I've checked
> the analysis and it claims that this approach should work for the 2nd
> test case. Am I missing something here? My code:
>
> from heapq import heappop, heappush
>
>
> def main():
>      T = int(input())  # the number of test cases
>
>      for case in range(1, T+1):
>          N, K = map(int, input().split())
>
>          h = [-N]
>
>          for _ in range(K):
>              chunk = -heappop(h)
>              if chunk & 1:
>                  if chunk == 1:
>                      min_s = max_s = 0
>                  else:
>                      min_s = max_s = chunk >> 1
>                      heappush(h, -min_s)
>                      heappush(h, -max_s)
>              else:
>                  max_s = chunk >> 1
>                  min_s = max_s - 1
>                  heappush(h, -min_s)
>                  heappush(h, -max_s)
>
>          print('Case #{}: {} {}'.format(case, max_s, min_s))
>
>
> main()
>
>
>
>
>
> --
> Regards,
>    Eugene
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Code Jam" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to google-code+unsubscr...@googlegroups.com.
> To post to this group, send email to google-code@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/google-code/f6b8ece9-0d14-5a39-d01f-d75d1acf9187%40gmail.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-code+unsubscr...@googlegroups.com.
To post to this group, send email to google-code@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/CAHaiWHNQ65sUwHzCPoxyseLq_DRRdiYjothB4W%3DZk9Dr25iwWg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to