Created
October 11, 2016 11:56
-
-
Save krofna/1a2aaaa0611051ae421da52b09429a44 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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