Solution to Contest Round 994 (Div-2) Problem (B)

Правка en2, от siddharth10111, 2024-12-22 22:44:52

2049B - pspspsps void solve() { ll n; cin >> n; string s; cin >> s; ll cp=0,cs=0;

// Counting p's and s's
forn
{
    if(s[i]=='p')
        cp++;
    if(s[i]=='s')
        cs++;
}

// Now if either p or s is absent....viola 
if(cp==0 || cs==0)
{
    cout<<"YES"<<endl;
    return;
}

// If there is only 1 s and its at the start...I have no problem
if(cs==1 && s[0]=='s')
{
    cout<<"YES"<<endl;
    return;
}

//Same for p but last index
if(cp==1 && s[n-1]=='p')
{
    cout<<"YES"<<endl;
    return;
}

/*
Lets see if you reach here then 
1. definitely there is atleast 1p and 1s
2. solution can be of the form spppp or ssssp with dots
3. if both s and p are greater than 1 then no solution is possible
4. if one of them occurs exactly once then it is not at the right place
     i.e first for s and last for p
5. therefore there can be a solution no more.
*/

cout<<"NO"<<endl;
return;

}

Теги constructive algorithms

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский siddharth10111 2024-12-22 22:44:52 1 Tiny change: '. therefor there can' -> '. therefore there can'
en1 Английский siddharth10111 2024-12-22 22:42:42 1165 Initial revision (published)