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

Previous submission (verdict: Wrong answer on test 2):
#pragma optimize GCC(2)

#pragma optimize GCC(3)

#pragma optimize GCC("Ofast")

#include <bits/stdc++.h>

#define endl '\n'

// #define int long long

#define lowbit(x) x & -x

using i64 = long long;

using u64 = unsigned long long;

using ld = long double;

const int maxn = 2e5 + 5;

const int inf = 0x7f7f7f7f;

const int mod = 1e9 + 7;



struct custom_hash 

{

	static uint64_t splitmix64(uint64_t x)

    {

		x ^= x << 13;

		x ^= x >> 7;

		x ^= x << 17;

		return x; 

	}

	size_t operator () (uint64_t x) const 

    {

		static const uint64_t FIXED_RANDOM = std::chrono::steady_clock::now().time_since_epoch().count(); // 时间戳

		return splitmix64(x + FIXED_RANDOM);

	}

};

char ch[550];

void solve()

{

    int n = 0;

    std::cin >> n;

    for (int i = 1; i <= n; i++) std::cin >> ch[i];

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

    {

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

        {

            if (i == 1 || i == n) continue;

            for (int j = 1; j <= n; j++)

            {

                if (ch[j] == 'p')

                {

                    if (j < i)

                    {

                        std::cout << "NO" << endl;

                        return;

                    }

                    else

                    {

                        int lenj = j, leni = n - i + 1;

                        int len = std::min(lenj, leni);

                        if (len != abs(j - i + 1))

                        {

                            std::cout << "NO" << endl;

                            return;

                        }

                    }

                }

            }

        }

    }

    std::cout << "YES" << endl;

}



signed main()

{

    std::ios::sync_with_stdio(false);

    std::cin.tie(nullptr); std::cout.tie(nullptr);

    //freopen("out.txt", "w", stdout);

    int t = 1;

    std::cin >> t;

    while(t--)

    {

        solve();

    }

    return 0;

}

Submission (verdict: Accepted):
#pragma optimize GCC(2)

#pragma optimize GCC(3)

#pragma optimize GCC("Ofast")

#include <bits/stdc++.h>

#define endl '\n'

// #define int long long

#define lowbit(x) x & -x

using i64 = long long;

using u64 = unsigned long long;

using ld = long double;

const int maxn = 2e5 + 5;

const int inf = 0x7f7f7f7f;

const int mod = 1e9 + 7;



struct custom_hash 

{

	static uint64_t splitmix64(uint64_t x)

    {

		x ^= x << 13;

		x ^= x >> 7;

		x ^= x << 17;

		return x; 

	}

	size_t operator () (uint64_t x) const 

    {

		static const uint64_t FIXED_RANDOM = std::chrono::steady_clock::now().time_since_epoch().count(); // 时间戳

		return splitmix64(x + FIXED_RANDOM);

	}

};

char ch[550];

void solve()

{

    int n = 0;

    std::cin >> n;

    for (int i = 1; i <= n; i++) std::cin >> ch[i];

    int sp = 0, pp = 0;

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

    {   

        if (ch[i] == 's') sp = i;

    }

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

    {

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

        {

            pp = i;

            break;

        }

    }

    if (sp == 0 || pp == 0)

    {

        std::cout << "YES" << endl;

        return;

    }

    if (sp > pp)

    {

        std::cout << "NO" << endl;

        return;

    }

    int lens = n - sp + 1, lenp = pp;

    if (std::min(lens, lenp) > pp - sp + 1)

    {

        std::cout << "NO" << endl;

        return;

    }

    std::cout << "YES" << endl;

}



signed main()

{

    std::ios::sync_with_stdio(false);

    std::cin.tie(nullptr); std::cout.tie(nullptr);

    //freopen("out.txt", "w", stdout);

    int t = 1;

    std::cin >> t;

    while(t--)

    {

        solve();

    }

    return 0;

}