提交时间:2022-05-04 21:25:06
运行 ID: 49220
#include<bits/stdc++.h> using namespace std; inline int read(){ int x=0;bool f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=0;ch=getchar();} while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();} return f?x:-x; } int n,t,numa[405],numb[405]; char a[405],b[405]; int main(){ n=read(),t=read(); for(int i=1;i<=n;i++) a[i]=getchar(),numa[i]=(a[i]=='R'); while(t--){ for(int i=1;i<=400;i++) if(a[i]=='R')b[i+2]='R',numb[i+2]=numa[i],numa[i]=0; for(int i=1;i<=402;i++) if(b[i]=='R'){ int j=i; while(a[j]=='G')j--; numa[j]+=numb[i]; a[j]='R'; } for(int i=1;i<=400;i++) if(a[i]=='G'||(a[i]=='R'&&numa[i]==1))putchar(a[i]); else if(a[i]=='R'&&numa[i])printf("R(%d)",numa[i]); for(int i=0;i<=404;i++)b[i]=' '; puts(""); } return 0; }