-
Notifications
You must be signed in to change notification settings - Fork 0
/
1722_D_Line.cpp
85 lines (61 loc) · 1.02 KB
/
1722_D_Line.cpp
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <iostream>
#include <vector>
#include <algorithm>
#include <array>
#include <cassert>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <random>
#include <iomanip>
#include <chrono>
#include <bitset>
#include <queue>
#include <complex>
#include <functional>
#define f(i,a,b) for(ll i = a;i < b;i++)
typedef long long ll;
using namespace std;
const ll INF = 1e9 + 7;
ll md = 998244353;
int const maxi = 2000;
int a[maxi][maxi];
void solve()
{
ll n;
cin>>n;
string s;
cin>>s;
ll res = 0 ;
vector<ll>v;
for(int i=0;i<n;i++)
{
if (s[i] == 'L') {
v.push_back((n - 1 - i) - i);
res += i;
}
else {
v.push_back(i - (n - 1 - i));
res += n - 1 - i;
}
}
sort(v.begin(), v.end(), greater<int>());
for(int i=0;i<n;i++)
{
if(v[i]>0)
{res += v[i];}
cout<<res<<" ";
}
cout<<"\n";
}
int main()
{
int t;
cin>>t;
while(t--)
{
solve();
}
return 0;
}