REARRSTR - Editorial

@adi28galaxyak

3
aaaaabbbbb
aabbccc
bab

plzz tell me how is that possibleā€¦ range of t is t<10^5 , so the data type of t should be long int, but in the following solution it is solved with ā€œintā€ onlyā€¦??
http://www.codechef.com/viewsolution/7017858

I have been getting a wrong answer for my code.
http://www.codechef.com/viewsolution/7019853

I would be glad if someone could give me a test case for which this fails.

Hereā€™s what i did. I implemented a Heap whose where the first 2 highest values are constantly updated. This is essentially a greedy approach since i take the 2 largest. So if it were aaabbc. It would take a nd b whose occurences are 3 and 2. It would reduce them to 2 and 1 respectively and append the character to a string. Now the heap essentially consists of a(2) b(1) c(1). Now remove a and b and repeat. Now you have a(1),c(1). Append and done. Also, be careful when the size of the heap is 1. E.i only one character is left. You can add it only if the number of occurences of that character are 1 and the previuos value appended is not equal to this one.

My code: http://www.codechef.com/viewsolution/7019973

can any one tell where i did wrongā€¦
i am getting runtime error(nzec) but it is working good in my system for all casesā€¦
http://www.codechef.com/viewsolution/7016382link text

@vedikaa Your solution fails here link text

@va1ts7_100 i hope you are confused. By the way range of int is ā€“2,147,483,648 to 2,147,483,647 .

1 Like

@hello_all Your code is runing fine. here is the linklink text i donā€™t see why it was giving tle.
Anyways u can place your strlen() out of for loop because in every iteration it will be called.

can i know the cases where my code fails.have been getting wrong answer even though i have tried a similar approach. here is my sol link text

@sidzekrom and @karthikm95
check for :
3
aaaaa
aa
aaaa

Please help me with the test case where my code fails:
http://www.codechef.com/viewsolution/7015299

Getting wrong answer but not sure why ā€¦Can anyone point out failing test case please

http://www.codechef.com/viewsolution/7021382

Help is appreciated !!

Failing cases plsā€¦
Did something very different.
http://www.codechef.com/viewsolution/7017138

@madhur123 thanks

@ankur1986 You forgot to add new line at the end of every test case. Rest is working fine i guess.

@Madhur . If you are saying changing System.out.print(new String(ans)) to System.out.println(new String(ans)) , I have already done that but still its not working .

Please help me with the test case where my code fails: http://www.codechef.com/viewsolution/7015299

@madhur123 ,what about the range of long int.?

Practice Link and Contest Link are swapped!


a test case where it fails?