1430D — String Deletion

Правка en1, от salt_n_ice, 2020-10-12 20:02:35

Problem Here is what I tried:

#include<iostream>
#include<vector>
#include<string>
using namespace std;
using ll = long long;

int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        string s;
        cin>>s;
        vector<ll> len, p;
        ll i=0, j=0;
        while(i<n && j<n)
        {
            while(j<n && s[i]==s[j])
                j++;
            p.push_back(j-i);
            i=j;
        }
        ll ans = 0;
        for(ll i=0; i<p.size(); ++i)
        {
            if(p[i]<2)
            {
                ans++;
                i++;
            }
            else
                ans++;
        }
        cout<<ans<<endl;
    }
}

Can someone briefly explain where am I going wrong?

Теги #greedy, #debug, #brute force, #string

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский salt_n_ice 2020-10-12 20:02:35 881 Initial revision (published)