Two Operations-Codeforces Gym Problem(ArabellaCPC2019) Doubt

Problem-https://codeforces.com/gym/102263/problem/M

What’s Wrong?- Getting Wrong Answer with my approach on test case 3.
Here is my approach-- https://ideone.com/4h5VZJ
I tried various test cases but i couldn’t find where it could possibly go wrong.

P.S-I also tried bruteforce way but it was giving me time limit exceeded on test case 3.

Can anyone help with this problem and their approach?

I don’t quite understand that you said that you tried a lot of test cases, because I randomly entered a case and then the result of your program was wrong,.
the case is “aab”, your results is “bb”, in fact, it’s “c”.

1 Like

Ohh i didn’t thought that even after appending, we can get pairs and they would form another one.
Lemme try now.Thanks again,you are saviour :slightly_smiling_face:

Can you check now?
Here: https://ideone.com/k2JiQ4
i tried 2 test cases.
aab its result should be c
aabbcc its result should be dcb and i am getting both correct.

But still the solution when i submit it gives me wrong answer :confused:

I tried “aaaaaab”, but your result is “cc”. Is not “d” ?
:thinking::thinking::thinking:

I quit now. :pensive:
Can u solve and send solution?

Sorry, I don’t think it’s a problem worth code about.

but let me try.

There is my solution:

# include <bits/stdc++.h>
using namespace std;
int main ()
{
    string s; cin >> s; 
    int l[26] = {};
    for (auto i: s) ++l[i - 'a'];
    for (int i = 0; i < 25; ++i) l[i + 1] += l[i] / 2, l[i] &= 1;
    for (int i = 25; i >= 0; --i) while (l[i]--) putchar(i + 'a');
    return 0;
}

2 Likes

Thanks :slightly_smiling_face: