比赛 2024暑假C班集训C 评测结果 WWWWWWWWWW
题目名称 W&B 最终得分 0
用户昵称 wzh0425 运行时间 2.242 s
代码语言 C++ 内存使用 4.11 MiB
提交时间 2024-07-12 09:18:09
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
int T,n,zm[100005],siz[100005],zs[5],ans,zm2[100005],siz2[100005],gs,t;
int gcd(int a,int b){
    if (a%b==0) return b;
    return gcd(b,a%b);
}
int main(){
    freopen("silly.in","r",stdin);
    freopen("silly.out","w",stdout);
    scanf("%d",&T);
    while (T--){
        gs=0,t=0,ans=0;
        memset(zs,0,sizeof(zs));
        scanf("%d",&n);
        for (int i=1;i<=n;i++){
            scanf("%d",&siz[i]);
            char s;
            scanf("%s",&s);
            if (s=='W'){
                zm[i]=1,zs[1]+=siz[i];
                if (gs==1){
                    siz2[t]+=siz[i];
                }else{
                    gs=1;
                    zm2[++t]=1;
                    siz2[t]=siz[i];
                }
            }
            else{
                zm[i]=2,zs[2]+=siz[i];
                if (gs==2){
                    siz2[t]+=siz[i];
                }else{
                    gs=2;
                    zm2[++t]=2;
                    siz2[t]=siz[i];
                }
            }
        }
        if (zs[1]==0){
            printf("%d\n",zs[2]);
            continue;
        }
        if (zs[2]==0){
            printf("%d\n",zs[1]);
            continue;
        }
        int t1=zs[1]/gcd(zs[1],zs[2]);
        int t2=zs[2]/gcd(zs[1],zs[2]);
        int ry=0,bl=0,flag=0;
        for (int i=1;i<=t;i++){
            if (zm2[i]==1){
                ry=bl*t1;
                if ((siz2[i]-ry)%t1!=0){
                    printf("1\n");
                    flag=1;
                    break;
                }else{
                    bl=(siz2[i]-ry)/t1;
                    if (bl!=0) ans++;
                }
            }else{
                ry=bl*t2;
                if ((siz2[i]-ry)%t2!=0){
                    printf("1\n");
                    flag=1;
                    break;
                }else{
                    bl=(siz2[i]-ry)/t2;
                    if (bl!=0) ans++;
                }
            }
        }
        if (flag==0){
            printf("%d\n",ans);
        }
    }
    return 0;
}