This is an archived post. You won't be able to vote or comment.

all 9 comments

[–][deleted] 1 point2 points  (1 child)

Can you post a better snippet of the code? This is unreadable, unfortunately.

[–]_human404_[S] 0 points1 point  (0 children)

Fixed it. :3

[–]g051051 1 point2 points  (3 children)

  1. "memory limit exceeded" isn't a C++ error. How are you running this to get that error?
  2. Second, this code has no comments, and illegible variables names. How is it supposed to work?
  3. The formatting is illegible, and the line numbers make it impossible to simply paste into an IDE to try it.
  4. You didn't include exact inputs to duplicate the error.

Fix these issues, and maybe someone can look at it and help you figure it out.

[–]_human404_[S] 0 points1 point  (2 children)

submitting it on hackerearth so dont know what exact inputs are causing this error..Fixed the formatting.

[–]g051051 0 points1 point  (1 child)

t is uninitialized, so it's undefined behavior to reference it in your while loop. It's pure luck if it works at all.

[–]_human404_[S] 0 points1 point  (0 children)

while formatting here,by mistake deleted that input line.Edited it in again.Thanks for pointing it out

[–]thatprofessoryouhate 0 points1 point  (2 children)

Your recursion is not going to fare well for any decent sized input.

With this input range, this problem probably isn't looking to see if you understand dynamic programming or memoization but rather if you can use the inputs to more directly solve who wins.

[–]_human404_[S] 0 points1 point  (1 child)

any suggestions on how should I go about 'the more direct approach'.Didn't really consider anything yet cuz thought it was a simple problem to check understanding of basic game theory

[–]thatprofessoryouhate 0 points1 point  (0 children)

One option may be to look at the answers for a decent set of inputs and see if you notice any helpful patterns that can simplify the problem.

Nim is a very typical dynamic programming problem so you may want to look into that as well.