Mostafa_Alaa99's blog

By Mostafa_Alaa99, history, 6 months ago, In English

About Div4E

here is my submission: 346532153

as you can see in my code I made this in the end, to make sure that this is really the error

if len(ans) != len(set(ans)): print(1 / 0)

but even though, it didn't give me runtime and um getting this

wrong answer points in output are not distinct (test case 189)

Btw, if someone knew my actual bug, plz tell me, I solved this problem already using PQ but I am struggling with its BS sol even I think I wrote the idea correctly

UPD1: I got the bug, it was I didn't check before x inclusively and valid as well as same with other side so I can fill the k

but this doesn't change the fact that the above error I was getting is strange, so I still need to know why I got it

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by Mostafa_Alaa99 (previous revision, new revision, compare).

»
6 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Here is the test you are failing:

Input:

1
5 20 20
16 15 7 17 11

Your Output:

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17

You can notice that you should be printing 20 points, but instead you are only printing 18, the two next points are from the next test, for the judge, it reads 20 points and compare, those 20 points contain duplicates, for your code it only checks the 18 points you printed, those contains no duplicates.

The issue with your solution is since got is equal to 0, is inserts it in the first while loop, in the second loop it finds that it was already inserted so it skips that loop, to fix that you should start the second while loop from last possible index before after and move backwardsm here is how I handled it:

after = a[i + 1] if i + 1 < n else float("inf")
cur = min(x, after - got)
while cur >= (a[i] + got) and k > 0 and str(cur) not in st:
    ans.append(cur)
    st.add(str(cur))
    cur -= 1
    k -= 1

Modified your submission and it got AC: 346539937

Now for the useless nitpicks:

Two spaces identation, cringe

You can just write assert False to get RTE instead of print(1/0)

  • »
    »
    6 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it +3 Vote: I do not like it

    Woow, this was so helpful comment, thanks too much I handled the bug too, it just missed to check some other available spaces which are the edges (check UPD1)

    Yes, I got that the error was that the size I am outputing is wrong — less than k — but I still think it is not a good msg from them, it really misled me

    I think I will always replace my 1 / 0 next time, with this cool assert, it didn't come to my mind before, I was always trying to make something strange like this or print text when they expect numbers ^_^