Problem: 2049B - pspspsps
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>

using namespace std;

int main()

{

    cin.tie(0);

    ios::sync_with_stdio(false);

    int t;

    cin >> t;

    while(t--)

    {

        int n;

        cin >> n;

        string s;

        cin >> s;

        map<char,int> mp;

        for(auto& x : s)

        {

            mp[x]++;

        }

        if(mp['.']==n) cout << "yes\n";

        else if(mp['s']==n) cout << "yes\n";

        else if(mp['p']==n) cout << "yes\n";

        else

        {

            int xp = -1,xs = -1;

            for(int i=0;i<n;i++)

            {

                if(s[i]=='p')

                {

                    xp = i;

                    break;

                }

            }

            for(int i=n-1;i>=0;i--)

            {

                if(s[i]=='s')

                {

                    xs = i;

                    break;

                }

            }

            if(xp<xs) cout << "no\n";

            else

            {

                if(mp['s']==1&&mp['p']==1)

                {

                    if(s[0]=='.'&&s[n-1]=='.') cout << "no\n";

                    else cout << "yes\n";

                }

                else if(mp['s']>1&&mp['p']>1) cout << "no\n";

                else

                {

                    if(mp['s']>1)

                    {

                        if(s[n-1]=='.') cout << "no\n";

                        else cout << "yes\n";

                    }

                    else

                    {

                        if(s[0]=='.') cout << "no\n";

                        else cout << "yes\n";

                    }

                }

            }

        }

    }

    return 0;

}

Submission (verdict: Accepted):
#include<bits/stdc++.h>

using namespace std;

int main()

{

    cin.tie(0);

    ios::sync_with_stdio(false);

    int t;

    cin >> t;

    while(t--)

    {

        int n;

        cin >> n;

        string s;

        cin >> s;

        map<char,int> mp;

        for(auto& x : s)

        {

            mp[x]++;

        }

        if(mp['.']==n) cout << "yes\n";

        else if(mp['s']==n) cout << "yes\n";

        else if(mp['p']==n) cout << "yes\n";

        else if(mp['.']+mp['s']==n||mp['.']+mp['p']==n) cout << "yes\n";

        else

        {

            int xp = -1,xs = -1;

            for(int i=0;i<n;i++)

            {

                if(s[i]=='p')

                {

                    xp = i;

                    break;

                }

            }

            for(int i=n-1;i>=0;i--)

            {

                if(s[i]=='s')

                {

                    xs = i;

                    break;

                }

            }

            if(xp<xs) cout << "no\n";

            else

            {

                if(mp['s']==1&&mp['p']==1)

                {

                    if(s[0]=='.'&&s[n-1]=='.') cout << "no\n";

                    else cout << "yes\n";

                }

                else if(mp['s']>1&&mp['p']>1) cout << "no\n";

                else

                {

                    if(mp['s']>1)

                    {

                        if(s[n-1]=='.') cout << "no\n";

                        else cout << "yes\n";

                    }

                    else

                    {

                        if(s[0]=='.') cout << "no\n";

                        else cout << "yes\n";

                    }

                }

            }

        }

    }

    return 0;

}