Nathan_McKane's blog

By Nathan_McKane, 4 years ago, In English

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

Full text and comments »

  • Vote: I like it
  • +14
  • Vote: I do not like it

By Nathan_McKane, history, 4 years ago, In English

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!!

Full text and comments »

  • Vote: I like it
  • -4
  • Vote: I do not like it

By Nathan_McKane, history, 4 years ago, In English

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.

Full text and comments »

  • Vote: I like it
  • +8
  • Vote: I do not like it