forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathequilibrium.cpp
68 lines (58 loc) · 1.11 KB
/
equilibrium.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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<string> split(string s) {
vector<string> v {""};
for(auto i : s) {
if(i == '[') {
v.push_back("[");
v.push_back("");
}
else if(i == ']') {
v.push_back("]");
v.push_back("");
}
else if(i == ',') {
v.push_back("");
}
else {
v.back().push_back(i);
}
}
return v;
}
void solve() {
string s;
cin >> s;
int d = 0;
map<ll,int> count;
vector<string> tokens = split(s);
int nums = 0;
for(auto i : tokens) {
if(i == "[") {
d++;
}
else if(i == "]") {
d--;
}
else if(i == "") {
}
else {
ll val = stoll(i);
count[val << d]++;
nums++;
}
}
int most = 0;
for(auto i : count) {
most = max(most, i.second);
}
cout << (nums - most) << endl;
}
int main() {
int cases;
cin >> cases;
while(cases--) {
solve();
}
}