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

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

using namespace std;

typedef long long ll;

typedef long double ld;

#define fu(i,a,b) for(int i = a; i<b; i++)

#define f(i,a) for(int i = 0; i<a; i++)

#define fi(i,a) for(int i = a-1; i>=0; i--)

const int MOD = 998244353;

const int NMAX = 200000;







int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);

    

  



    int t;

    cin >> t;

    while (t--) {

        int n;

        cin >> n;

        

        string s;



        int t=0;



        cin >> s;



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

        {

            t=1;

        }

        else if(s[n-1]=='p')

        {

            t=1;

        }

        else

        {

            t=1;

            f(i,n)

            {

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

                {

                    t=0;

                }

            }

        }



        char m = '.';





        f(i,n)

        {





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

            {

                t=0;

            }







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

            {

                m = 's';

            }

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

            {

                m = 'p';

            }



        }



        if(t==1)

        {

            cout << "YES" << endl;

        }

        else

        {

            cout << "NO" << endl;

        }







    }



    return 0;

}



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

using namespace std;

typedef long long ll;

typedef long double ld;

#define fu(i,a,b) for(int i = a; i<b; i++)

#define f(i,a) for(int i = 0; i<a; i++)

#define fi(i,a) for(int i = a-1; i>=0; i--)

const int MOD = 998244353;

const int NMAX = 200000;







int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);

    

  



    int t;

    cin >> t;

    while (t--) {

        int n;

        cin >> n;

        

        string s;



        int t=0;



        cin >> s;



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

        {

            t=1;

            fu(i,1,n-1)

            {

                if(s[i]!='s'&& s[i]!='.')

                {

                    t=0;

                }

            }



        }

        else if(s[n-1]=='p')

        {

            t=1;

            fu(i,1,n)

            {

                if(s[i]!='p'&& s[i]!='.')

                {

                    t=0;

                }

            }

        }

        else

        {

            t=1;

            f(i,n)

            {

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

                {

                    t=0;

                }

            }

        }



        char m = '.';





        f(i,n)

        {





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

            {

                t=0;

            }







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

            {

                m = 's';

            }

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

            {

                m = 'p';

            }



        }



        if(t==1)

        {

            cout << "YES" << endl;

        }

        else

        {

            cout << "NO" << endl;

        }







    }



    return 0;

}