比赛 |
2024暑假C班集训C |
评测结果 |
TAAAAAATTT |
题目名称 |
W&B |
最终得分 |
60 |
用户昵称 |
彭欣越 |
运行时间 |
10.519 s |
代码语言 |
C++ |
内存使用 |
4.04 MiB |
提交时间 |
2024-07-12 09:52:07 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
int t,n,cnt,a[100010],b[100010];
long long ans,sum1,sum2,res1,res2;
int main () {
freopen("silly.in","r",stdin);
freopen("silly.out","w",stdout);
cin >> t;
while (t--) {
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
ans=0,res1=0,res2=0,cnt=0,sum1=0,sum2=0;
cin >> n;
for (int i=1;i<=n;i++) {
int x;
char s;
cin >> x >> s;
cnt++;
if (s=='B') {
a[cnt]=x;
sum1+=x;
}else{
b[cnt]=x;
sum2+=x;
}
}
//cout << sum1 <<' '<< sum2 <<endl;
if (sum1==0) {
cout << sum2 <<endl;
continue;
}else if (sum2==0) {
cout << sum1 <<endl;
continue;
}else if (sum1==1||sum2==1) {
cout << 1 <<endl;
continue;
}
int flag=0;
//cout << sum1 <<' '<< sum2 <<endl;
int t=min(sum1,sum2);
for (int i=2;i<=t;i++) {
while (sum1%i==0&&sum2%i==0) {
sum1/=i;
sum2/=i;
flag=1;
}
}
//cout << sum1 <<' '<< sum2 <<endl;
if (flag==0) {
cout << 1 <<endl;
continue;
}
res2+=b[1];
res1+=a[1];
//cout << res1 <<' '<< res2 <<endl;
for (int i=2;i<=cnt;i++) {
if (b[i]==0) {
for (int j=1;j<=a[i];j++) {
res1++;
//cout << res1 <<' '<< res2 <<' '<< sum1 <<' '<< sum2 <<endl;
if (res1%sum1==0&&res2%sum2==0&&res1/sum1==res2/sum2) {
ans++;
res1=0;
res2=0;
res1+=a[i]-j;
break;
}
}
}else{
for (int j=1;j<=b[i];j++) {
res2++;
//cout << res1 <<' '<< res2 <<' '<< sum1 <<' '<< sum2 <<endl;
if (res1%sum1==0&&res2%sum2==0&&res1/sum1==res2/sum2) {
//cout << res1 <<' '<< res2 <<endl;
ans++;
res1=0;
res2=0;
res2+=b[i]-j;
break;
}
}
}
}
cout << ans <<endl;
}
return 0;
}