Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <cstring>
- #include <algorithm>
- using namespace std;
- #define mp make_pair
- #define f first
- #define s second
- typedef pair <int, int> pii;
- const int N = 1e5 + 5;
- pii a[N];
- int n, c;
- void cntBoys(char p[], int v, int& fir, int& sec)
- {
- fir = sec = 0;
- for (int i = 0; i < v; i++)
- if (i%2 == 0 && p[i] == 'B') fir++;
- else if (i%2 && p[i] == 'B') sec++;
- }
- bool fun(pii x, pii y)
- {
- return x.f - x.s >= y.f - y.s;
- }
- int main()
- {
- //freopen("physed.in", "r", stdin);
- //freopen("physed.out", "w", stdout);
- cin >> n;
- int len, ones = 0, all = 0;
- char s[105];
- for (int i = 0; i < n; i++)
- {
- scanf("%s", s);
- len = strlen(s);
- if (len%2)
- {
- cntBoys(s, len, a[c].f, a[c].s);
- c++;
- } else
- {
- int e1, e2;
- cntBoys(s, len, e1, e2);
- ones += e1;
- all += max(e1, e2);
- }
- }
- if (!c)
- {
- cout << ones;
- return 0;
- }
- sort(a, a + c, fun);
- int t = (c + 1) / 2;
- for (int i = 0; i < t; i++)
- all += a[i].f;
- for (int i = t; i < c; i++)
- all += a[i].s;
- cout << all;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement