Изменения рейтингов за последние раунды временно удалены. Скоро они будут возвращены. ×

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

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

Why does this code get accepted 55539853 and this does not 55539543?

I believe the time complexity of 1st submission is O(k(n+m)) for k bfs and then O(nklog(k)) for sorting each node.

Can someone tell the complexity of the second code because of which it is failing.

For getting s smallest element I am using slog(s) complexity in bfs in 2nd submission.

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

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

your accepted solutions runs in 1.7 second, which is close to the time limit, so sort vector is faster than popping from priority queue one by one, and therefore you get TLE?

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

    Also, please learn to ask question instead of just posting codes. You can say like: solution 1 uses priority_queue and popping one by one while solution uses vector and sorting it. This will reduce the time taken for people to help you and therefore it will be more likely for someone to help.

    • »
      »
      »
      5 лет назад, # ^ |
        Проголосовать: нравится -13 Проголосовать: не нравится

      But ain't it the same thing. Sorting n elements O(nlog(n)) Popping priority queue O(log(n)) for 1 element so O(nlog(n)) for n elements??

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

        Yes, it is the same in terms of time complexity. But having the same time complexity does not imply that the code is equally fast. For instance, sorting the code 1 time is O(nlog(n)), but sorting it twice is also O(nlog(n)), but is the performance of both code going to be the same?