-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy path1333D.cpp
More file actions
executable file
·59 lines (52 loc) · 1022 Bytes
/
1333D.cpp
File metadata and controls
executable file
·59 lines (52 loc) · 1022 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Problem Code: 1333D
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
void head_turns(int n, int k, string& s) {
int i, j, mx = 0;
bool done = false;
vector<vector<int>> moves;
while (!done) {
done = true;
vector<int> move;
for (int i = 0; i < n - 1; i++)
if (s[i] == 'R' && s[i + 1] == 'L') {
mx++;
done = false;
swap(s[i], s[i + 1]);
move.push_back(++i);
}
if (!done)
moves.push_back(move);
}
if (moves.size() > k || mx < k) {
cout << "-1" << '\n';
return;
}
// endl is slow as it flushes the buffer each time hence '\n'
i = j = 0;
while (i < moves.size()) {
if (moves.size() - i < k)
cout << 1 << " " << moves[i][j++] << '\n';
else {
cout << moves[i].size() - j;
while (j < moves[i].size())
cout << " " << moves[i][j++];
cout << '\n';
}
if (j == moves[i].size()) {
j = 0;
i++;
}
k--;
}
}
int main() {
int n, k;
string s;
cin >> n >> k >> s;
head_turns(n, k, s);
return 0;
}