比赛 2024暑假C班集训C 评测结果 WWWWWWWWWW
题目名称 W&B 最终得分 0
用户昵称 ┭┮﹏┭┮ 运行时间 1.858 s
代码语言 C++ 内存使用 3.89 MiB
提交时间 2024-07-12 09:02:00
显示代码纯文本
#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 + a[i].s)ans++,sb = 0,sw -= (s2 * (sb / s1) - a[i].s);
        if(a[i].op)
            if(sw % s2 == 0 && s1 * (sw / s2) <= sb + a[i].s)ans++,sw = 0,sb -= (s1 * (sw / s2) - 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;
    
}