やるだけ。
class MathContest { public: int countBlack(string B, int R) { const int b = 1; deque<int> q; for (int i = 0; i < (int)R; ++i) { for (int j = 0; j < (int)B.size(); ++j) { q.push_back(B[j] == 'B'); } } int cnt = 0; int ord = 1; int rev = 0; while (q.size()) { int n; if (ord) { n = q.front(); q.pop_front(); } else { n = q.back(); q.pop_back(); } n ^= rev; cnt += n == b; if (n == b) { rev ^= 1; } else { ord ^= 1; } } return cnt; } };