fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. const int Mod=1e9+7;
  5. const ll INF = 10000000000000;
  6. const int N = 1e6+7;
  7.  
  8. void solve() {
  9. int n;
  10. cin >> n;
  11. string s;
  12. cin >> s;
  13. vector<int> a(n+1,1);
  14. for(int i=0;i<n;i++){
  15. if(s[i]=='p'){
  16. for(int j=i+1;j<n;j++){
  17. if(s[j]=='s'){
  18. cout << "NO\n";
  19. return;
  20. }
  21. }
  22. }
  23. if(s[i]=='s'){
  24. for(int j=i+1;j<n;j++){
  25. if(s[j]=='p'){
  26. if(j-i+1<min(j+1,n-i)){
  27. cout << "NO\n";
  28. return;
  29. }
  30. }
  31. }
  32. }
  33. }
  34. cout << "YES\n";
  35. }
  36.  
  37. int main(){
  38. ios::sync_with_stdio(false);
  39. cin.tie(nullptr);
  40.  
  41. int t;
  42. cin >> t;
  43. while (t--) solve();
  44.  
  45. return 0;
  46. }
  47.  
Success #stdin #stdout 0.01s 5304KB
stdin
9
4
s.sp
6
pss..s
5
ppppp
2
sp
4
.sp.
8
psss....
1
.
8
pspspsps
20
....................
stdout
YES
NO
YES
YES
NO
NO
YES
NO
YES