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;

#define rep(b) for (ll i = 0; i < b; ++i)

#define f(i, a, b) for (ll i = a; i <= b; ++i)

#define vl vector<ll>

#define vp vector<pair<ll, ll>>

#define ALL(x) (x).begin(), (x).end()

#define eb emplace_back

#define ia(a, n)     \

    vector<ll> a(n); \

    f(i, 0, n - 1) cin >> a[i]



const ll mod = 1e9 + 7;



long long power(long long base, long long exp) {

    long long result = 1;

    

    while (exp > 0) {

        // If exp is odd, multiply the result by base

        if (exp % 2 == 1) {

            result *= base;

        }

        

        // Square the base and halve the exponent

        base *= base;

        exp /= 2;

    }

    

    return result;

}

void solve(){

    int n ;

    cin >> n ;

    string s ;

    cin >> s ;

    int posP = 0;

    int posS = 0;

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

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

            posP = i ;

            break ;

        }



    }



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

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

            posS = i ;

            break ;

        }

    }

    //cout << "s " << posS << " " << "p " << posP << endl;

    if(posS > posP){

        //cout << "1" << endl;

        cout << "NO" << endl;

        return  ;

    }



    vector <int> a ;

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

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

            a.push_back(i+1);

        }

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

            a.push_back(n - i) ;

        }

    }

    sort(a.begin() , a.end()) ;

    if(a.size() == 0){

        cout <<  "YES" << endl;

        return ;

    }

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

        if(a[i] == a[i-1] && a[i] != n){

           // cout << "2" << endl;

            cout << "NO" << endl;

            return ;

        }

    }

    cout << "YES" << endl;

    



}



int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.flush();

    ll t;

    cin >> t;



    while (t--)

    {

        solve();

    }



    return 0;

}



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

using namespace std;

typedef long long ll;

#define rep(b) for (ll i = 0; i < b; ++i)

#define f(i, a, b) for (ll i = a; i <= b; ++i)

#define vl vector<ll>

#define vp vector<pair<ll, ll>>

#define ALL(x) (x).begin(), (x).end()

#define eb emplace_back

#define ia(a, n)     \

    vector<ll> a(n); \

    f(i, 0, n - 1) cin >> a[i]



const ll mod = 1e9 + 7;



long long power(long long base, long long exp) {

    long long result = 1;

    

    while (exp > 0) {

        // If exp is odd, multiply the result by base

        if (exp % 2 == 1) {

            result *= base;

        }

        

        // Square the base and halve the exponent

        base *= base;

        exp /= 2;

    }

    

    return result;

}

void solve(){

    int n ;

    cin >> n ;

    string s ;

    cin >> s ;

    int posP = -1;

    int posS = -1;

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

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

            posP = i ;

            break ;

        }



    }



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

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

            posS = i ;

            break ;

        }

    }

    //cout << "s " << posS << " " << "p " << posP << endl;

    if(posS > posP && posP != -1){

        //cout << "1" << endl;

        cout << "NO" << endl;

        return  ;

    }



    vector <int> a ;

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

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

            a.push_back(i+1);

        }

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

            a.push_back(n - i) ;

        }

    }

    sort(a.begin() , a.end()) ;

    if(a.size() == 0){

        cout <<  "YES" << endl;

        return ;

    }

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

        if(a[i] == a[i-1] && a[i] != n){

           // cout << "2" << endl;

            cout << "NO" << endl;

            return ;

        }

    }

    cout << "YES" << endl;

    



}



int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.flush();

    ll t;

    cin >> t;



    while (t--)

    {

        solve();

    }



    return 0;

}