forked from DionysiosB/CodeForces
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1722D-Line.cpp
More file actions
33 lines (27 loc) · 740 Bytes
/
1722D-Line.cpp
File metadata and controls
33 lines (27 loc) · 740 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
#include <iostream>
#include <vector>
#include <algorithm>
typedef long long ll;
int main(){
std::ios_base::sync_with_stdio(false);
ll t; std::cin >> t;
while(t--){
ll n; std::cin >> n;
std::string s; std::cin >> s;
std::vector<ll> diffs(n, 0);
ll sum(0);
for(ll p = 0; p < n; p++){
ll cur = (s[p] == 'L') ? p : n - p - 1;
ll mx = (p > (n - p - 1)) ? p : (n - p - 1);
sum += cur;
ll diff = mx - cur;
diffs[p] = diff;
}
sort(diffs.rbegin(), diffs.rend());
for(ll p = 0; p < n; p++){
sum += diffs[p];
std::cout << sum << " ";
}
std::cout << std::endl;
}
}