Codeforces Round #632 (Div. 2) D-Challenges in school №41(模拟好题)

 Challenges in school №41

 

 

 

 

 

 学习博客:here

AC_Code;

 

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 const int maxn = 3e6+10;
 5 const int inf = 0x3f3f3f3f;
 6 const double pi = acos(-1.0);
 7 #define rep(i,first,second) for(ll i=first;i<=second;i++)
 8 #define dep(i,first,second) for(ll i=first;i>=second;i--)
 9 
10 int n,k;
11 char str[3005];
12 vector<int>v[maxn];
13 ll maxk,mink,d;
14 
15 void solve(){
16     int p=0,p2=0,kk=mink;
17     while( kk<k ){
18         cout<<"1 "<<v[p][p2]<<'\n';//用cout<<"1 "<<v[p][p2]<<endl;就超时了
19         p2++;
20         if( p2==v[p].size() ){
21             p2=0;
22             p++;
23         }
24         else kk++;
25     }
26     cout<<v[p].size()-p2;
27     for(int i=p2;i<v[p].size();i++){
28         cout<<' '<<v[p][i];
29     }
30     cout<<'\n';//用cout<<endl就超时了
31     p++;
32 
33     while( p<mink ){
34         cout<<v[p].size();
35         for(int i=0;i<v[p].size();i++){
36             cout<<' '<<v[p][i];
37         }
38         cout<<'\n';//用cout<<endl就超时了
39         p++;
40     }
41 }
42 
43 void check(int p){
44     for(int i=1;i<n; ){
45         if( str[i]=='R' && str[i+1]=='L' ){
46             str[i]='L';
47             str[i+1]='R';
48             v[p].push_back(i);
49             i+=2;
50         }
51         else{
52             i++;
53         }
54     }
55 }
56 
57 int main(){
58     scanf("%d%d",&n,&k);
59     scanf("%s",str+1);
60 
61     check(0);
62     while( v[mink].size() && mink<=k ){
63         maxk += v[mink].size();
64         mink++;
65         check(mink);
66     }
67     if( mink<=k && k<=maxk ){
68         solve();
69     }
70     else{
71         printf("-1\n");
72     }
73     return 0;
74 }

 

posted @ 2020-04-09 18:13  swsyya  阅读(171)  评论(0编辑  收藏  举报

回到顶部