记录编号 |
590864 |
评测结果 |
AAAAAAAAAA |
题目名称 |
W&B |
最终得分 |
100 |
用户昵称 |
┭┮﹏┭┮ |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
1.865 s |
提交时间 |
2024-07-12 13:10:37 |
内存使用 |
3.93 MiB |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5+10;
const ll mod = 1e9+7;
ll read(){
ll x = 0,f = 1;char c = getchar();
for(;c < '0' || c > '9';c = getchar())if(c == '-')f = -1;
for(;c >= '0' && c <= '9';c = getchar())x = (x<<1) + (x<<3) + c-'0';
return x * f;
}
int n,t,s1,s2,ans;
struct made{
bool op;
int s;
}a[N];
void solve(){
n = read();
s1 = s2 = ans = 0;
for(int i = 1;i <= n;i++){
char c;int x = read();cin>>c;
a[i] = {c == 'B',x};
if(c == 'B')s1 += x;
else s2 += x;
}
if(s1 == 0 || s2 == 0)return printf("%d\n",s1 | s2),void();
int d = __gcd(s1,s2);
s1 /= d,s2 /= d;
// printf("***** %d %d\n",s1,s2);
int sb = 0,sw = 0;
for(int i = 1;i <= n;i++){
if(!a[i].op){
if(sb % s1 == 0 && s2 * (sb / s1) > sw && s2 * (sb / s1) <= sw + a[i].s)ans++,sw -= (s2 * (sb / s1) - a[i].s),sb = 0;
else sw += a[i].s;
}
if(a[i].op){
if(sw % s2 == 0 && s1 * (sw / s2) > sb && s1 * (sw / s2) <= sb + a[i].s)ans++,sb -= (s1 * (sw / s2) - a[i].s),sw = 0;
else sb += a[i].s;
}
}
printf("%d\n",ans);
}
int main(){
freopen("silly.in","r",stdin);
freopen("silly.out","w",stdout);
t = read();
while(t--)solve();
return cerr<<clock()<<"ms"<<endl,0;
}