Skip to content

Instantly share code, notes, and snippets.

@krofna
Created October 11, 2016 11:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krofna/1a2aaaa0611051ae421da52b09429a44 to your computer and use it in GitHub Desktop.
Save krofna/1a2aaaa0611051ae421da52b09429a44 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
using namespace std;
int T, B, W;
int gcd(int a, int b)
{
return ((b == 0) ? a : gcd(b, a % b));
}
void Add(char b)
{
switch (b)
{
case 'B': B += b; break;
case 'W': W += b; break;
}
}
void First(char b)
{
return b == 'B';
}
int main()
{
cin >> T;
while (T--)
{
int n;
cin >> n;
B = W = 0;
vector<int> V(n);
char a, b;
cin >> V[0] >> a;
Add(a);
for (int i = 1; i < n; ++i)
{
cin >> V[i];
cin >> b;
Add(b);
if (b == a)
{
V[i - 1] += V[i];
--i;
--n;
}
a = b;
}
//
if (!B || !W)
{
cout << B + W << '\n';
continue;
}
int itr = First(b);
int bw[2] = {0, 0};
for (int i = 0; i < n; ++i)
{
bw[(itr + i) % 2)] += V[i];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment