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

Автор Nathan_McKane, 4 года назад, По-английски

I was trying a problem in which I wanted to delete some elements from the set while iterating over the elements of the set.

Link to the problem: Problem C, Educational Round #108

Pseudo Code

for(condition in list_of_conditions):
   for(element X in set):
      if(condition(X) is false):
         remove X from the set
      else:
         answer += result(X)

However, I failed to implement this in an optimized way. I wonder what are some of the shortest and most optimized codes to implement this idea...

Please share your ideas. Thank you!

Failed implementation (Runtime error)

My failed implementation

Accepted implementation

My accepted implementation

Полный текст и комментарии »

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

Автор Nathan_McKane, история, 4 года назад, По-английски

Link to the Question: 576A

Link to my code: Code

I was trying this question on Number theory and faced this error "Wrong Answer cannot distinguish 1 and 727". I couldn't detect the reason for the incorrect output. My code runs fine and gives correct result for the same input (test case 16) on other platform's IDEs. Please help!!

Полный текст и комментарии »

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

Автор Nathan_McKane, история, 4 года назад, По-английски

I was trying a question on searching/sorting (Problem link) and i defined my own comparator for in-built sort(). It produced ambiguous output for the input (Error Code Link). However, when i changed the "<=" to "<" in my comparator, the code (Accepted Code Link) worked properly and was accepted. I dont know how this happened and what was the significance of changing the comparison condition.

Полный текст и комментарии »

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