fork download
  1. #include <bits/stdc++.h>
  2. #include <string.h>
  3. using namespace std;
  4. #define ll long long
  5.  
  6. void solve(){
  7. int n;
  8. cin>>n;char s[n];int a[n]={0};int b[n]={0};int k=0;
  9. for(int i=0;i<n;i++){cin>>s[i];
  10. if(s[i]=='p'){k=1;a[i]=i+1;}
  11. if(s[i]=='s'){b[i]=n-i;}
  12. if(k && s[i]=='s'){k=2;}}
  13. if(k==2){cout<<"NO"<<endl;return;}
  14. int l=0,r=n-1;
  15. for(int i=n-1;i>=0;i--){
  16. int j=0;
  17. while(b[j]==0 && j<i){j++;}
  18. if(a[i]&&b[j]){if(min(a[i],b[j])>i-j+1){cout<<"NO"<<endl;return;}}
  19.  
  20.  
  21. }
  22.  
  23.  
  24.  
  25. cout<<"YES"<<endl;}
  26.  
  27.  
  28.  
  29.  
  30. int main() {
  31. int t;
  32. cin>>t;
  33. while(t--){solve(); }
  34. return 0;
  35. }
Success #stdin #stdout 0.01s 5280KB
stdin
1
5
.s..p
stdout
YES