Problem link: 1654C - Alice and the Cake
I tried solving the problem with a different approach. It would be great if someone helps me analyze the time and space complexity of my submission, because I feel it should be within constraints and somehow it fails!
Thanks for your time reading :)
Problem solved: see ACGN reply
You are getting a MLE because you are using
std::map
see my reply below
Your program probably ran into an infinite loop because your variables
val
andoddval
overflowedint
.AC submission by replacing
int
withlong long
in your declaration ofval
andoddval
: 152648929By the way,
std::map
s do not cause MLE sincestd::map
also has space complexity O(n). An infinite loop, on the other hand, creates a large call stack which leads to MLE.that's why
#define int long long
is usefulwhat do you think about
#define int short
as suggested by Sparky Masteri think you can