-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1722D.cpp
More file actions
46 lines (37 loc) · 934 Bytes
/
1722D.cpp
File metadata and controls
46 lines (37 loc) · 934 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
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int t;
cin >> t;
while (t--) {
int n;
string s;
cin >> n >> s;
ll base_value = 0;
vector<ll> gains;
for (int i = 0; i < n; i++) {
if (s[i] == 'L') {
base_value += i;
gains.push_back((n - i - 1) - i);
} else {
base_value += n - i - 1;
gains.push_back(i - (n - i - 1));
}
}
sort(gains.rbegin(), gains.rend());
vector<ll> result(n);
ll current_value = base_value;
for (int k = 0; k < n; k++) {
if (gains[k] > 0) {
current_value += gains[k];
}
result[k] = current_value;
}
for (ll x : result) {
cout << x << " ";
}
cout << '\n';
}
return 0;
}