Блог пользователя siddharth10111

Автор siddharth10111, история, 12 часов назад, По-английски

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;

}

Полный текст и комментарии »

  • Проголосовать: нравится
  • -11
  • Проголосовать: не нравится

Автор siddharth10111, история, 2 недели назад, По-английски

Problem: 2040C - Ordered Permutations

My Submission: 295743692

A solution to the C problem of contest 992, I was really glad to finally manage to solve it (though after the contest)....so much so that I'm sharing this. Do feel free to share your views and feedback.

Полный текст и комментарии »

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится