1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
int n,ans,ls=-1,cnt;
bool flag;
char lst=0;
inline void work(signed CASE=1,bool FINAL_CASE=false) {
n=read(); vector<int> v;
for(int i=1;i<=n;i++) {
char c=nc();
if(c==lst) {
v.back()++;
} else {
v.pb(1);
lst=c;
}
}
for(auto &x:v) {
if(x&1) {
flag=!flag;
x=(x==1)?0:x;
} else if(flag) {
x=(x==2)?0:x;
}
ans+=flag;
}
for(int i=0;i<sz(v);i++) {
if(0!=v[i] && ls!=(i&1)) {
ls=i&1;
cnt++;
}
}
printf("%lld %lld\n",ans,cnt>1?cnt:1);
return;
}
signed main() {
// ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); //freopen(".in", "r", stdin);//freopen(".out", "w", stdout);
signed T=(signed)read();//scanf("%d",&T);//cin>>T;
for(signed CASE=1; CASE<=T; CASE++) { //
//printf("Case #%d: ",CASE); //printf("Case %d: ",CASE); //printf("Case #%d: \n",CASE); //printf("Case %d: \n",CASE);
work(CASE,CASE==T);
if(CASE!=T) {
lst=cnt=ans=0;
flag=false;
ls=-1;
}
}
return 0;
}
|