Files
contests/2023/rcpc/d1/editorial/E. Anton Would Approve This Problem - greedy.cpp
2024-04-22 16:45:09 +03:00

39 lines
726 B
C++

/// Gheorghies Alexandru - greedy solution
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;
const ll LGMAX=20,NMAX=3e5+5;
void tc(){
ll n,ans=0,len=0;
string s;
cin>>n>>s;
for(ll i=0;i<n;i++){
if(i && s[i]!=s[i-1]) len++;
else{
ans+=(len+1)/3;
len=0;
}
}
ans+=(len+1)/3;
cout<<ans<<'\n';
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif // ONLINE_JUDGE
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
ll t; cin>>t; while(t--)
tc();
return 0;
}