Problem: 2049B - pspspsps
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
// include

#include<bits/stdc++.h>



using namespace std;



// define

#define fi    first

#define se    second



#define pub   push_back

#define pob   pop_back

#define puf   push_front

#define pof   pop_front

#define eb    emplace_back

#define upb   upper_bound

#define lwb   lower_bound



#define left  VAN

#define right TAN



#define sz(a)               (int)a.size()

#define all(a)              (a).begin(),(a).end()

#define rall(a)             (a).begin(),(a).end()

#define sort_and_unique(a)  sort(all(a));(a).resize(unique(all(a))-a.begin())

#define max_                max_element

#define min_                min_element



// another define

using ll  = long long;

using ld  = long double;

using pii = pair<int, int>;

using pil = pair<int, ll>;

using pli = pair<ll, int>;

using pll = pair<ll, ll>;

using mii = map<int, int>;

using mil = map<int, ll>;

using mli = map<ll, int>;

using mll = map<ll, ll>;

using vi  = vector<int>;

using vl  = vector<ll>;

using vvi = vector<vi>;

using vvl = vector<vl>;



// random

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());



// templates

template<class X, class Y>

    bool maximize(X &x, const Y &y) {

        if (y > x) {

            x = y;

            return (true);

        } else return (false);

    }



template<class X, class Y>

    bool minimize(X &x, const Y &y) {

        if (y < x) {

            x = y;

            return (true);

        } else return (false);

    }



template<class T>

    void print(const T &a, const int &l, const int &r) {

        for (int i = l; i <= r; i++)

            cout << a[i] << ' ';

        cout << '\n';

    }



// limit

const int oo = 2e9;



// function

void yesno(bool x) {

    cout << (x ? "YES\n" : "NO\n");

}



void solve() {

    int n;

    string str;

    cin >> n >> str;

    int p = -1, s = -1;

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

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

            s = i;

        } else if (str[i] == 'p') {

            if (p == -1) {

                p = i;

            }

        }

    }

    if (s == -1 || p == -1) {

        yesno(1);

    } else {

        if (s > p) {

            yesno(0);

        } else {

            int a = 0;

            int b = 0;

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

                a |= (str[i] == '.');

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

                b |= (str[i] == '.');

            yesno(!(a & b));

        }

    }

}



int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0); cout.tie(0);

    int t = 1;

    cin >> t;



    while (t--) solve();

    return 0;

}





Submission (verdict: Wrong answer on test 2):
// include

#include<bits/stdc++.h>



using namespace std;



// define

#define fi    first

#define se    second



#define pub   push_back

#define pob   pop_back

#define puf   push_front

#define pof   pop_front

#define eb    emplace_back

#define upb   upper_bound

#define lwb   lower_bound



#define left  VAN

#define right TAN



#define sz(a)               (int)a.size()

#define all(a)              (a).begin(),(a).end()

#define rall(a)             (a).begin(),(a).end()

#define sort_and_unique(a)  sort(all(a));(a).resize(unique(all(a))-a.begin())

#define max_                max_element

#define min_                min_element



// another define

using ll  = long long;

using ld  = long double;

using pii = pair<int, int>;

using pil = pair<int, ll>;

using pli = pair<ll, int>;

using pll = pair<ll, ll>;

using mii = map<int, int>;

using mil = map<int, ll>;

using mli = map<ll, int>;

using mll = map<ll, ll>;

using vi  = vector<int>;

using vl  = vector<ll>;

using vvi = vector<vi>;

using vvl = vector<vl>;



// random

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());



// templates

template<class X, class Y>

    bool maximize(X &x, const Y &y) {

        if (y > x) {

            x = y;

            return (true);

        } else return (false);

    }



template<class X, class Y>

    bool minimize(X &x, const Y &y) {

        if (y < x) {

            x = y;

            return (true);

        } else return (false);

    }



template<class T>

    void print(const T &a, const int &l, const int &r) {

        for (int i = l; i <= r; i++)

            cout << a[i] << ' ';

        cout << '\n';

    }



// limit

const int oo = 2e9;



// function

void yesno(bool x) {

    cout << (x ? "YES\n" : "NO\n");

}



void solve() {

    int n;

    string str;

    cin >> n >> str;

    int p = -1, s = -1;

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

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

            s = i;

        } else if (str[i] == 'p') {

            if (p == -1) {

                p = i;

            }

        }

    }

    if (s == -1 || p == -1) {

        yesno(1);

    } else {

        if (s > p) {

            yesno(0);

        } else {

            int a = 0;

            int b = 0;

            for (int i = 0; i < s; i++) {

                if (str[i] == 'p') {

                    yesno(0);

                    return;

                }

                a |= (str[i] == '.');

            }

            for (int i = n - 1; i > p; i--) {

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

                    yesno(0);

                    return;

                }

                b |= (str[i] == '.');

            }

            yesno(!(a & b));

        }

    }

}



int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0); cout.tie(0);

    int t = 1;

    cin >> t;



    while (t--) solve();

    return 0;

}