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. string s;
  11. cin >> n >> s;
  12. bool ok = false;
  13. for(int i=0;i<n-1;i++){
  14. if(i%2==0){
  15. if(s[i]=='1' && s[i+1]=='1') ok=true;
  16. }
  17. }
  18. if(n%2==1){
  19. if(ok || s[0]=='1') cout << "YES\n";
  20. else cout << "NO\n";}
  21. else if(n%2==0){
  22. if(ok || s[0]=='1' || s[n-1]=='1') cout << "YES\n";
  23. else cout << "NO\n";
  24. }
  25. }
  26. int main(){
  27. ios::sync_with_stdio(false);
  28. cin.tie(nullptr);
  29.  
  30. int t;
  31. cin >> t;
  32. while (t--) solve();
  33.  
  34. return 0;
  35. }
  36.  
Success #stdin #stdout 0.01s 5292KB
stdin
5
2
11
3
010
12
101111111100
10
0111111011
8
01000010
stdout
YES
NO
YES
YES
NO