fork download
  1. #include <bits/stdc++.h>
  2. #define endl "\n"
  3. #define Dark_knight
  4. #include <complex.h>
  5. #include<ext/pb_ds/assoc_container.hpp>
  6. #include<ext/pb_ds/tree_policy.hpp>
  7. using namespace __gnu_pbds;
  8. using namespace std;
  9. typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> orderedSet;
  10. typedef long long ll;
  11. #define int long long
  12. const int N = 2e5 + 2;
  13. const int mod = 1073741824;
  14. long long arr[N]={};
  15. long long pref[N]={};
  16. int lcm(int a , int b ) {
  17. return a/__gcd(a,b) *b;
  18. }
  19. signed main() {
  20. ios::sync_with_stdio(false);
  21. cin.tie(nullptr);
  22. cout.tie(nullptr);
  23. int t ;
  24. cin >> t;
  25. while(t--) {
  26. int n ;
  27. cin >> n ;
  28. string s ;
  29. cin >> s;
  30. int ctr = 0 , mx = 0 ;
  31. for(int i = 0 ; i < n ; i++) {
  32. if(s[i]=='0') {
  33. ctr++;
  34. }
  35. else {
  36. mx=max(ctr,mx);
  37. ctr=0;
  38. }
  39. }
  40. mx=max(ctr,mx);
  41. int begin = 0 ;
  42. for(int i = 0 ; i < n ; i++) {
  43. if(s[i]=='0') {
  44. begin++;
  45. }
  46. else {
  47. break;
  48. }
  49. }
  50. int trail = 0 ;
  51. for(int i = n-1 ; i >= 0 ; i++ ) {
  52. if(s[i]=='0') {
  53. trail++;
  54. }
  55. else {
  56. break;
  57. }
  58. }
  59. cout<<max(mx,begin+trail)<<endl;
  60.  
  61. }
  62.  
  63. }
  64.  
  65.  
  66.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
0