/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Accepted 4ms 580.0 KiB
#3 Accepted 3ms 320.0 KiB
#4 Accepted 2ms 580.0 KiB
#5 Accepted 2ms 576.0 KiB
#6 Accepted 2ms 692.0 KiB
#7 Accepted 2ms 832.0 KiB
#8 Accepted 2ms 744.0 KiB

Code

///******* In the name of ALLAH, Who is Most Gracious, Most Merciful *******///
///******* There is no God but ALLAH, MUHAMMAD(S.A.W) is the Messenger of ALLAH. *******///
///******* Every soul shall taste death.*******///

//  AL-HAMDULILLAH    //  AL-HAMDULILLAH     //  AL-HAMDULILLAH    //  AL-HAMDULILLAH
//  AL-HAMDULILLAH    //  AL-HAMDULILLAH     //  AL-HAMDULILLAH    //  AL-HAMDULILLAH
//  AL-HAMDULILLAH    //  AL-HAMDULILLAH     //  AL-HAMDULILLAH    //  AL-HAMDULILLAH
//  AL-HAMDULILLAH    //  AL-HAMDULILLAH     //  AL-HAMDULILLAH    //  AL-HAMDULILLAH
//  AL-HAMDULILLAH    //  AL-HAMDULILLAH     //  AL-HAMDULILLAH    //  AL-HAMDULILLAH

/**************************************************************************************
    ___  _          _   _  ___ ___  ________ _   _ _    _____ _     _      ___  _   _
   / _ \| |        | | | |/ _ \|  \/  |  _  | | | | |  |_   _| |   | |    / _ \| | | |
  / /_\ | |  ____  | |_| / /_\ | .  . | | | | | | | |    | | | |   | |   / /_\ | |_| |
  |  _  | | |____| |  _  |  _  | |\/| | | | | | | | |    | | | |   | |   |  _  |  _  |
  | | | | |____    | | | | | | | |  | | |/ /| |_| | |____| |_| |___| |___| | | | | | |
  \_| |_\_____/    \_| |_\_| |_\_|  |_|___/  \___/\_____\___/\_____\_____\_| |_\_| |_/

***************************************************************************************/

//  AL-HAMDULILLAH    //  AL-HAMDULILLAH     //  AL-HAMDULILLAH    //  AL-HAMDULILLAH
//  AL-HAMDULILLAH    //  AL-HAMDULILLAH     //  AL-HAMDULILLAH    //  AL-HAMDULILLAH
//  AL-HAMDULILLAH    //  AL-HAMDULILLAH     //  AL-HAMDULILLAH    //  AL-HAMDULILLAH


//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdlib.h>
#include<string.h>
#include<math.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>

#define 	ll              long long
#define 	size1           1000001
#define 	bm              1000000007   //bigmod
#define		reset(arr,n,i)  fill(arr,arr+n,i)  //cbrt(n) means cube root
#define		rset(arr,x)  	memset(arr,x,sizeof(arr))
#define		_ceil(x,y)      ((x)/(y))+(((x)%(y))>0)
#define		INF             (ll)1e18 + 10
#define		mod             1e9 + 7//998244353;
#define 	endl            "\n"

#define		_cpy(c,a,n)     for(int i=0;i<n;i++) c[i]=a[i];
#define 	_iin(a,n)       int a[n]; for(int i=0;i<n;i++) cin>>a[i]
#define 	_lin(a,n)       ll a[n]; for(int i=0;i<n;i++) cin>>a[i]
#define 	_in(a,n)        for(int i=0;i<n;i++) cin>>a[i]
#define 	_out(a,n)       for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl
#define		_celi(x,y)      (x+y-1)/(y)  //use this version of _ceil [note: ceil is risky]
#define		eps             0.0000000001

#define 	fopr()          freopen("input.txt", "r", stdin)
#define 	fopw()          freopen("output.txt", "w", stdout)
#define 	FastIO          ios_base::sync_with_stdio(false), cin.tie(0)

// Math :
void		mns(int *x, int *y)		{
	if(*x>=*y) *x-=*y, *y=0;
	else *y-=*x, *x=0;
}
int			log_2(ll n)				{
	int cnt=0;
	while(n/2) cnt++, n/=2;
	return cnt;
}
int			log2_(ll i)				{
	return i ? __builtin_clzll(1) - __builtin_clzll(i) : -1;
}
// Debuging :
#define		_dbg(_x,_y,_z)  cout<<_x<<" "<<_y<<" "<<_z<<endl
#define		_dbl			cout<<"_________________ "<<endl
#define		_db(_x,_y)      cout<<_x<<" "<<_y<<endl
#define     OK              cout<<"Ok"<<endl;

using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;


//Sparse Table
/*const int MAXN=200007;
const int LOG=18;
int min_st[MAXN][LOG];
int max_st[MAXN][LOG];
int log_table[MAXN + 7];

void buildSparseTables(int n,int arr[]) {
    log_table[1]=0;
    for (int i=2; i<=n;i++)
        log_table[i]=log_table[i / 2]+1;

    for (int i = 0;i<n;i++) {
        min_st[i][0]=arr[i];
        max_st[i][0]=arr[i];
    }

    for (int j = 1;(1 << j)<= n;j++)
        for (int i=0; i+(1 << j)<= n; i++) {
            min_st[i][j]=min(min_st[i][j - 1], min_st[i + (1 << (j - 1))][j - 1]);
            max_st[i][j]=max(max_st[i][j - 1], max_st[i + (1 << (j - 1))][j - 1]);
        }
}

int queryMin(int L, int R) {
    int j = log_table[R - L + 1];
    return min(min_st[L][j], min_st[R - (1 << j) + 1][j]);
}

int queryMax(int L, int R) {
    int j = log_table[R - L + 1];
    return max(max_st[L][j], max_st[R - (1 << j) + 1][j]);
}*/


/*const int N=200001;
map<int,int>id_col,mxber;
int n,m,k,col[N],mx=0,total=0;
vector<int>grp[N];
bool vis[N]= {0};

void dfs(int node) {
	vis[node]=1;
	total++;
	mxber[col[node]]++;
	mx=max(mx,mxber[col[node]]);

	for(auto child:grp[node]) {
		if(vis[child]) continue;
		dfs(child);
	}
	return;
}

const int N=1001;
ll fact[N];

void facto(){
	fact[1]=1;
	for(int i=2;i<=N;i++){
		fact[i]=fact[i-1]*i;
	}
}

ll binexp(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a)%mod;
        a = (a * a)%mod;
        b >>= 1;
    }
    return res;
}

ll MMI(ll den){
	return binexp(den,mod-2);
}

ll nCr(ll n, ll r){
	ll den=MMI((fact[n-r]%mod*fact[r]%mod)%mod);
	return (fact[n]%mod*den)%mod;
}

ll lcm(ll a, ll b){
    return (a/__gcd(a,b))*b;
}*/

void solve() {
	int n;
	cin>>n;
	
	string str;
	cin>>str;
	
	for(int i=0;i<n;i++){
		if(str[i]=='1') str[i]='0';
		else str[i]='1';
	}
	
	int cnt=0,mx=0;
	if(str[0]=='1') cnt=1;
	
	for(int i=1;i<n;i++){
		if(str[i-1]='1' && str[i]=='1') cnt++;
		else {
			mx=max(mx,cnt);
			if(str[i]=='1') cnt=1;
			else cnt=0;
		}
	}
	
	mx=max(mx,cnt);
	
	cout<<mx<<endl;
}

int main() {
	FastIO;
	int n=1;
	cin>>n;
	while(n--) {
		solve();
	}
	return 0;
}
//written by MAMUN

/*  Cautions:
	1.array out of bound!!! [check array size and last accessed index]
	2.signed integer overflow!!! [int*int!=ll @typecast(ll) one of them or, multiply with 1LL]
	3.floating point numbers numbers are equal if the difference between them is less than 1e-9 [better way to compare floating point numbers]
	4.any square number when divided by 4 must have a remainder of either 0 or 1.
*/


/********************************************************************************************************************************************************
 _   _            _   _       _____          _     _   _       _                    _ _          ______                   _           _           _
| \ | |          | | | |     |  ___|        | |   | | | |     (_)                  (_) |         | ___ \                 | |         | |         | |
|  \| | ___  _ __| |_| |__   | |__  __ _ ___| |_  | | | |_ __  ___   _____ _ __ ___ _| |_ _   _  | |_/ / __ _ _ __   __ _| | __ _  __| | ___  ___| |__
| . ` |/ _ \| '__| __| '_ \  |  __|/ _` / __| __| | | | | '_ \| \ \ / / _ \ '__/ __| | __| | | | | ___ \/ _` | '_ \ / _` | |/ _` |/ _` |/ _ \/ __| '_ \
| |\  | (_) | |  | |_| | | | | |__| (_| \__ \ |_  | |_| | | | | |\ V /  __/ |  \__ \ | |_| |_| | | |_/ / (_| | | | | (_| | | (_| | (_| |  __/\__ \ | | |
\_| \_/\___/|_|   \__|_| |_| \____/\__,_|___/\__|  \___/|_| |_|_| \_/ \___|_|  |___/_|\__|\__, | \____/ \__,_|_| |_|\__, |_|\__,_|\__,_|\___||___/_| |_|
                                                                                           __/ |                     __/ |
                                                                                          |___/                     |___/
*********************************************************************************************************************************************************/

Information

Submit By
Type
Submission
Problem
P1113 Fliping Game
Contest
Brain Booster #7
Language
C++17 (G++ 13.2.0)
Submit At
2024-11-05 14:51:06
Judged At
2024-11-11 02:32:22
Judged By
Score
100
Total Time
4ms
Peak Memory
832.0 KiB