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

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

using namespace std;

#define ios ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)

typedef pair<int,int> PII;

typedef long long ll;

void sol(){

  int n;

  cin>>n;

  string s;

  cin>>s;

  s=" "+s;

  bool st[n+1];

  memset(st,false,sizeof st);

  int op=0;

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

  {

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

  	{

  		op=i;

  		break;

	  }

  }

  if(op==0)

  {

  	cout<<"YES"<<endl;

  	return;

  }

  vector<PII> ans(n+1);

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

  {

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

  	{

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

        {

        	if(st[j]==false)

        	{

        		ans[j]={i,n};

        	//	cout<<i<<j<<" "<<" "<<"s"<<endl;

			}

			else

			{

				int x=ans[j].first;

				int y=ans[j].second;

				if(i>x) x=i;

				if(n<y) y=n;

				ans[j]={x,y};

			//	cout<<i<<j<<" "<<" "<<x<<" "<<y<<" "<<"s"<<endl;

			}

			st[j]=true;

		}

	}

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

	{

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

        {

        	if(st[j]==false)

        	{

        		ans[j]={1,i};

        	//	cout<<i<<j<<" "<<" "<<"q"<<endl;

			}

			else

			{

				int x=ans[j].first;

				int y=ans[j].second;

				if(1>x) x=1;

				if(i<y) y=i;

				ans[j]={x,y};

			//	cout<<i<<j<<" "<<" "<<x<<" "<<y<<" "<<"q"<<endl;

			}

			st[j]=true;

		}

	}

  }

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

  {

  	int x=ans[i].first;

	int y=ans[i].second;

//	cout<<x<<" "<<y<<endl;

	if(x>y||x==0||y==0)

	{

	cout<<"NO"<<endl;	

	return;

	}

  }

  cout<<"YES"<<endl;

}

int main()

{

	ios;

	int t;

	cin>>t;

	while(t--)

	{

		sol();

	}

	return 0;

} 

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

using namespace std;

#define ios ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)

typedef pair<int,int> PII;

typedef long long ll;

void sol(){

  int n;

  cin>>n;

  string s;

  cin>>s;

  s=" "+s;

  bool st[n+1];

  memset(st,false,sizeof st);

  int op=0;

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

  {

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

  	{

  		op=i;

  		break;

	  }

  }

  if(op==0)

  {

  	cout<<"YES"<<endl;

  	return;

  }

  int sum=0;

  vector<PII> ans(n+1);

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

  {

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

  	{

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

        {

        	if(st[j]==false)

        	{

        		ans[j]={i,n};

        //		cout<<i<<j<<" "<<" "<<"s"<<endl;

			}

			else

			{

				int x=ans[j].first;

				int y=ans[j].second;

				if(i>x) x=i;

				if(n<y) y=n;

				ans[j]={x,y};

	//		cout<<i<<j<<" "<<" "<<x<<" "<<y<<" "<<"s"<<endl;

			}

			st[j]=true;

		}

	}

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

	{

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

        {

        	if(st[j]==false)

        	{

        		ans[j]={1,i};

        	//	cout<<i<<j<<" "<<" "<<"q"<<endl;

			}

			else

			{

				int x=ans[j].first;

				int y=ans[j].second;

				if(1>x) x=1;

				if(i<y) y=i;

				ans[j]={x,y};

			//	cout<<i<<j<<" "<<" "<<x<<" "<<y<<" "<<"q"<<endl;

			}

			st[j]=true;

		}

	}

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

	{

		sum++;

	}

	}

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

  {

  	int x=ans[i].first;

	int y=ans[i].second;

//	cout<<x<<" "<<y<<endl;

	if(x>y||x==0||y==0)

	{

		if(x==0||y==0)

	{sum--;

	if(sum==-1)

	cout<<"NO"<<endl;

		}	

	else 

	cout<<"NO"<<endl;	

	return;

	}

  }

  cout<<"YES"<<endl;

}

int main()

{

	ios;

	int t;

	cin>>t;

	while(t--)

	{

		sol();

	}

	return 0;

}