提交时间:2022-04-14 14:58:37

运行 ID: 48653

#include <bits/stdc++.h> using namespace std; int n,T,r[310]; bool g[310]; char a[310]; int main() { cin>>n>>T; for(int i=1; i<=n; i++) { cin>>a[i]; if(a[i]=='G') g[i]=true; else r[i]++; } for(int i=1; i<=T; i++) { for(int j=n; j>=1; j--) { if(r[j]>0&&g[j+3]==0) r[j+3]+=r[j],r[j]=0; else if(r[j]>0&&g[j+3]==1) { int k=j; while(g[--k]==0) r[k]+=r[j],r[j]=0; } else if(g[j]=1) g[j+1]=1,g[j]=0; } for(int j=1; j<=310; j++) { if(r[j]==1) cout<<'R'; else if(g[j]==1) cout<<'G'; else if(r[j]>1) cout<<"R("<<r[j]<<")"; if(r[j]==0&&g[i]==0) continue; } cout<<endl; } return 0; }