fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int t;
  6. cin >> t;
  7. while(t--){
  8. int n;
  9. cin >> n;
  10. vector<int>v;
  11. string s;
  12. cin >> s;
  13. for(int i=0; i<n; i++){
  14. int k = s[i] - '0';
  15. v.push_back(k);
  16. }
  17. for(int i=0 ;i<n-1; i++){
  18. if(s[i] == s[i+1])
  19. v.push_back(1);
  20. else if(s[i] != s[i+1])
  21. v.push_back(0);
  22. }
  23. int x=0, y=0;
  24. for(int i=0; i<v.size(); i++){
  25. if(v[i] == 1)
  26. x++;
  27. else if(v[i] == 0)
  28. y++;
  29. }
  30. if(y>x)cout << "YES" << endl;
  31. else
  32. cout << "NO" << endl;
  33. }
  34. return 0;
  35. }
Success #stdin #stdout 0.01s 5292KB
stdin
3
2
00
2
11
2
10
stdout
YES
NO
YES