-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathD.cpp
More file actions
59 lines (51 loc) · 1.11 KB
/
D.cpp
File metadata and controls
59 lines (51 loc) · 1.11 KB
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
//
// Created by kayoung on 2022/09/02.
//
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
void solve();
int main() {
int T;
cin >> T;
for (int i = 0; i < T; i++) {
solve();
}
return 0;
}
void solve() {
long long n;
cin >> n;
string pos;
cin >> pos;
int bestRes[2 * 100000] = {};
for (int i = 0; i < n / 2 + 1; i++) {
if (bestRes[i] != 0) break;
bestRes[i] = bestRes[n - 1 - i] = n - 1 - i;
}
priority_queue<long long> pQueue = {};
int currRes[2 * 100000] = {};
long long total = 0;
for (int i = 0; i < n; i++) {
if (pos[i] == 'L') {
currRes[i] = i;
} else {
currRes[i] = n - 1 - i;
}
if (bestRes[i] != currRes[i]) {
pQueue.push(bestRes[i] - currRes[i]);
}
total += currRes[i];
}
for (int i = 0; i < n; i++) {
if (pQueue.empty()) {
cout << total << " ";
} else {
total += pQueue.top();
pQueue.pop();
cout << total << " ";
}
}
cout << endl;
}