-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathE.cpp
46 lines (40 loc) · 804 Bytes
/
E.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
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
int64_t compute(vector<int64_t> &a) {
int64_t md = a[(int)a.size() / 2];
int64_t res = 0;
for(auto u: a) {
res += abs(u - md);
}
return res;
}
void run_cases() {
int n;
cin >> n;
vector<int64_t> x;
for(int i=0;i<n;i++) {
char ch;
cin >> ch;
if(ch == '*') {
x.push_back(i + 1);
}
}
for(int i=0;i<x.size();i++) {
x[i] -= i;
}
sort(x.begin(), x.end());
if(x.empty()) {
cout << "0\n";
return;
}
cout << compute(x) << '\n';
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(nullptr);
int tests = 1;
cin >> tests;
for(int test = 1;test <= tests;test++) {
run_cases();
}
}