siddharth10111's blog

By siddharth10111, history, 8 hours ago, In English

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;

}

Full text and comments »

  • Vote: I like it
  • -9
  • Vote: I do not like it

By siddharth10111, history, 2 weeks ago, In English

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.

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it