Problem statement:: https://www.codechef.com/FLMOCK01/problems/ALTARAY
My solution:: https://www.codechef.com/viewsolution/28784297
Getting Runtime Error :: SIGCONT
Please Help !!!
Problem statement:: https://www.codechef.com/FLMOCK01/problems/ALTARAY
My solution:: https://www.codechef.com/viewsolution/28784297
Getting Runtime Error :: SIGCONT
Please Help !!!
Use the following recursive equation for longest alternating prefix for every a[i].
I am using dp[i] for representing the longest alternating prefix from i^{th} index in a[i].
Start filing the dp[i] array from n - 2 index as we know the answer for dp[n - 1].
Then just print the dp[i] from 0 to n - 1.
NOTE: I am using zero-based indexing for filling the data and traversing the dp[i] array.
Solution Source-Code Link: https://www.codechef.com/viewsolution/27603345
Thanks for reading.
Peace
Can you explain what is wrong in my solution ???
In short, SIGSTOP tells a process to â€śhold onâ€ť and SIGCONT tells a process to â€śpick up where you left offâ€ť. This can work really well for rsync jobs since you can pause the job, clear up some space on the destination device, and then resume the job. The source rsync process just thinks that the destination rsync process is taking a long time to respond.
You can read about the above runtime-error code SIGCONT here: SIGSTOP and SIGCONT
EDIT: Your code is not giving SIGCONT signal i.e. runtime-error rather its a wrong answer, that means you are missing something.
Your code is giving incorrect output for the following test-case:
2
4
-1000000000 -1000000000 -1000000000 -1000000000
4
-1000000000 1000000000 -1000000000 1000000000
Your code has a lot of bugs, I am listing them down:
If you look at the constraints, the value of a[i] can go as large as 10^{9} and as small as 10^{-9}. Moreover you are using multiplication to check whether the number is -ve or not, which leads to an integer overflow as you have defined the data-types of res
and memo[n]
as int
. I will leave the math to yourself to figure it out, why integer-overflow .
Why are you checking for x == n
?
Why are you using recursion when there is a simple iterative solution to the problem using DP. Think about what if the constraints for N is of the order of 10^{18}, then there would be a lot of recursive calls which will lead to runtime-error.
Some Suggestions on your code:
if-else
block, also the indentation of your code is messy.{}
even if there is only one statement associated with if-else
or loops
, it makes code easier to read.At last you can refer to the edited version of your accepted solution. I wouldnâ€™t suggest you to implement it again, rather find out another way of thinking to solve the problem, I already gave you the idea here.
Thanks for reading.
Peace
No problem