Comments

After seeing the solution, it feels like the question was really easy all along.

Is Problem C genuinely difficult, or does it only seem hard to me?

On N29 → Codeforces Round 1054 (Div. 3), 14 months ago
0

ok got it thanks...

On N29 → Codeforces Round 1054 (Div. 3), 14 months ago
0

Can someone please check why my solution for D is wrong?

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
#define mod 1000000007

void solve()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    
    int op1 = 0;
    int op2 = 0;
    
    int l = 0;
    int r = n-1;
    while(l<n && s[l] == 'a')
    {
        l++;
    }
    while(r >= 0 && s[r] == 'a')
    {
        r--;
    }
    for(int i=l; i<=r; ++i)
    {
        if(s[i] == 'a')
        {
            if(i-l > r-i)
            {
                op1 += r-i;
                r--;
            }
            else
            {
                op1 += i-l;
                l++;
            }
        }
    }
    l = 0;
    r = n-1;
    while(l < n && s[l] == 'b')
    {
        l++;
    }
    while(r>= 0 && s[r] == 'b')
    {
        r--;
    }
    for(int i=l; i<=r; ++i)
    {
        if(s[i] == 'b')
        {
            if(i-l > r-i)
            {
                op2 += r-i;
                r--;
            }
            else
            {
                op2 += i-l;
                l++;
            }
        }
    }
  
    cout<<min(op1,op2)<<endl;
}


int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        solve();
    }
}

this my code

Ok got it, thanks

i want to know how to solve this problem without converting into set.

In problem B

Original problem deals with n sets S1, S2, ..., Sn and asks whether there are at least three ways to choose some sets so that every integer from 1 to m appears in at least one chosen set.

Now, suppose instead of sets, we are given n arrays that may contain duplicate elements.

How should we approach this problem efficiently when arrays may have duplicates?

.

.

.

..

On cry → Codeforces Round 1050 (Div. 4), 14 months ago
0

In problem E

I’m having trouble figuring out how binary search could be applied here. Could someone please explain or share an outline of how this problem can be solved using binary search?

In problem E

I’m having trouble figuring out how binary search could be applied here. Could someone please explain or share an outline of how this problem can be solved using binary search?