LAPIN: Different results for the same testcase

Solution link: https://www.codechef.com/viewsolution/35863084
Here are two cases in the screenshot. Have a look at case ‘ababc’

That submission processes the testcases in the reverse order.

Replace:

while(i--) {

with

for(i=0; i<t; i++) {
1 Like

The program worked but its still showing runtime error. Although memory usage is far below what others have used and there isn’t any posibility of division by zero. Could you please help me figure out the problem?

Please link to the solution instead of pasting a screenshot :slight_smile:

Edit:

Oh, I think I can figure it out:

char str[t][1000];

The 1000 is not enough to hold the largest input string - there’s the null-terminator to consider as well, remember!

Also - there’s absolutely no need to read in and store all test inputs - just read in one; process it; output the result; read in the next; process that; etc.

Edit2:

There’s also no need to test for t>100 - the constraints are guarantees you are given, not things you have to check.

2 Likes

Sorry, I would take care of that next time. :sweat_smile:
Here’s the link: https://www.codechef.com/viewsolution/35863482

1 Like

Thanks - see my Edit(s) :slight_smile:

1 Like

Oh, right! Thanks

1 Like

SIGSEGV is segmentation fault. Which is most probably access out of bounds.
Division by 0 is SIGFPE (floating point exception).
There is SIGABRT (Abort) too, but I’m not sure what it is.
And exceeding memory limit will give you code MLE. And ofc exceeding time limit gives TLE.

Justing putting this out here, so you can debug your next RE easily.

2 Likes