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

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

I'm trying the problem: 1923D - Slimes

Problem Summary: an element a -> a can take the adjacent element b if b is strictly less than a. After taking b, a is increased by b and b is removed. For an element, what is the min number of operations need among all other elements to take the element?

Approach: Prefix Sum + Binary Search

Calculate prefix and binary search on the right side to find the closest index where the sum is greater than the curr element. Then reverse the array and do it again (to search on the left side). Note: there must at least two unique element which is handled by map.

Submission: 284865983

What's wrong in my code?

Can anyone please help me to debug?

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

»
6 недель назад, # |
Rev. 2   Проголосовать: нравится +1 Проголосовать: не нравится
How to find the wrong test case?

Your code mishandles the case where duplicates gather in the middle of the array. In the wrong case you encounter:

4
1 2 2 2

Your code thinks the 3th slime can eat 2th slime and then eat 4th slime, which is impossible.

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

    Thanks for your help. I really appreciate your time.

    Can you please also tell me more about how to find the exact wrong test case?

    Like, how can I identify that a particular test case is wrong? What code should I write?