https://codeforces.ml/contest/1333/problem/D

话不多说,参考博客:https://www.cnblogs.com/stelayuri/p/12664236.html

写得不能再清楚了!!!

附自己写的代码抄的代码~~

#include <bits/stdc++.h>
using namespace std;
const int MAXN=5e5+5;
const int mod=1e9+7;
typedef long long ll;
//typedef __int128 LL;
const int inf=0x3f3f3f3f;
const long long INF=0x3f3f3f3f3f3f3f3f;
int n,k;
char a[3005];
vector<int>v[3000005];
void check(int p)
{
    for(int i=1;i<=n;i++)
    {
        if(a[i]=='R'&&a[i+1]=='L')
        {
            swap(a[i],a[i+1]);
            v[p].push_back(i);
            i++;
        }
    }
}
int main()
{
    scanf("%d%d%s",&n,&k,a+1);
    int mink=0,maxk=0;
    check(0);
    while(v[mink].size()&&mink<=k)
    {
        maxk+=v[mink].size();
        mink++;
        check(mink);
    }
    if(mink>k||maxk<k)printf("-1\n");
    else
    {
        int p1=0,p2=0,kk=mink;
        while(kk<k)
        {
            printf("1 %d\n",v[p1][p2]);
            p2++;
            if(p2==v[p1].size())p2=0,p1++;
            else kk++;
        }
        printf("%d ",v[p1].size()-p2);
        for(int i=p2;i<v[p1].size();i++)printf("%d%c",v[p1][i],i==v[p1].size()-1?'\n':' ');
        p1++;
        while(p1<mink)
        {
            printf("%d ",v[p1].size());
            for(int i=0;i<v[p1].size();i++)printf("%d%c",v[p1][i],i==v[p1].size()-1?'\n':' ');
            p1++;
        }
    }
    return 0;
}
View Code

 

posted on 2020-04-10 20:52  MZRONG  阅读(129)  评论(0编辑  收藏  举报