记录编号 |
590865 |
评测结果 |
TWWWWWWTTT |
题目名称 |
W&B |
最终得分 |
0 |
用户昵称 |
彭欣越 |
是否通过 |
未通过 |
代码语言 |
C++ |
运行时间 |
10.152 s |
提交时间 |
2024-07-12 13:54:56 |
内存使用 |
4.03 MiB |
显示代码纯文本
#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) {
if (res2%sum2!=0) continue;
int k=res2/sum2*sum1-res1;
if (k<0||k>a[i]) continue;
ans++;
res1=0;
res2=0;
res1+=a[i]-k;
}else{
if (res1%sum1!=0) continue;
int k=res1/sum1*sum2-res2;
if (k<0||k>b[i]) continue;
ans++;
res1=0;
res2=0;
res2+=b[i]-k;
}
}
cout << ans <<endl;
}
return 0;
}