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

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

using namespace std;





   void solve(){

      int n;

      cin>>n;

      string s;

      cin>>s;

      int pp=0;

      int ss=0;

      int dot=0;

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

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

            pp++;

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

            ss++;



         }else{

            dot++;

         }

        

      }

      // cout<<pp<<endl;

      if(ss==n||pp==n||dot==n){

         cout<<"YES"<<endl;

         return ;

      }

        bool flag=false;

        int cnt=0;

        int cnt2=0;

        bool s1=false;

        bool s2=false;

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

         if(s[i]=='s' &&cnt==0){

            cnt++;

            flag=true;

            s1=true;

         }

         if(flag==true&&s[i]=='p'){

            cnt++;

            s2=true;

         }

         if(s[i]=='.'&&s1){

            cnt++;

         }





      }

      bool found=true;

           bool p1=false;

           bool p2=false;

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

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

            cnt2++;

            p1=true;

         }

         if(s[i]=='p'&&found==true){

            cnt2++;

            found=false;

            p2=true;

         }

         if(p1==true&&p2==false&&s[i]=='.'){

            cnt2++;

         }

      }

      if(cnt==n||cnt2==n){

         cout<<"YES"<<endl;

         return ;

      }

      cout<<"NO"<<endl;

   }



   int main(){

   int t;

   cin>>t;



   while(t--){

      solve();



   }



return 0;

}

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

using namespace std;





   void solve(){

      int n;

      cin>>n;

      string s;

      cin>>s;

      int pp=0;

      int ss=0;

      int dot=0;

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

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

            pp++;

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

            ss++;



         }else{

            dot++;

         }

        

      }

      // cout<<pp<<endl;

      if(ss+dot==n||pp+dot==n||dot==n){

         cout<<"YES"<<endl;

         return ;

      }

        bool flag=false;

        int cnt=0;

        int cnt2=0;

        bool s1=false;

        bool s2=false;

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

         if(s[i]=='s' &&cnt==0){

            cnt++;

            flag=true;

            s1=true;

         }

         if(flag==true&&s[i]=='p'){

            cnt++;

            s2=true;

         }

         if(s[i]=='.'&&s1){

            cnt++;

         }





      }

      bool found=true;

           bool p1=false;

           bool p2=false;

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

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

            cnt2++;

            p1=true;

         }

         if(s[i]=='p'&&found==true){

            cnt2++;

            found=false;

            p2=true;

         }

         if(p1==true&&p2==false&&s[i]=='.'){

            cnt2++;

         }

      }

      if(cnt==n||cnt2==n){

         cout<<"YES"<<endl;

         return ;

      }

      cout<<"NO"<<endl;

   }



   int main(){

   int t;

   cin>>t;



   while(t--){

      solve();



   }



return 0;

}