提交时间:2022-04-15 19:54:40

运行 ID: 48771

#include<bits/stdc++.h> using namespace std; int n,T,tong[1010]; int Red[110],Green[110]; void walk(int n,int m){ for(int i=1;i<=n;i++) Red[i]+=3; for(int i=1;i<=m;i++) Green[i]++; } void init(int m){ memset(tong,0,sizeof(tong)); for(int i=1;i<=m;i++) tong[Green[i]]++; } void chuai(int n){ for(int i=1;i<=n;i++) while(tong[Red[i]]) Red[i]--; } int main(){ char c; int N1=0,N2=0,l1,l2,sum; scanf("%d%d",&n,&T); for(int i=1;i<=n;i++){ cin>>c; if(c=='R') Red[++N1]=i; else Green[++N2]=i; } for(int t=1;t<=T;t++){ walk(N1,N2),init(N2),chuai(N1),l1=l2=1; sort(Red+1,Red+N1+1),sort(Green+1,Green+N2+1); for(int i=1;i<=n;i++) if((l1<=N1&&Red[l1]<Green[l2])||l2>N2){ printf("R"),sum=1; while(l1<=N1&&Red[l1]==Red[l1+1]) i++,l1++,sum++; l1++; if(sum>1) printf("(%d)",sum); } else printf("G"),l2++; printf("\n"); } return 0; }