Untitled

 avatar
unknown
c_cpp
9 months ago
1.1 kB
17
Indexable
#include <bits/stdc++.h>
using namespace std;
#define ll long long

void solve() {
  int n;
  string s;
  cin >> n >> s;

  set<int> exists;
  for (int i = 0; i < n; i++) exists.insert(i);

  set<int> a, b;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'A') a.insert(i);
    else b.insert(i);
  }

  while (!a.empty()) {
    vector<pair<int, int>> found;
    for (int j = *a.begin(); j < n; j++) {
      auto iter = b.lower_bound(j);
      if (iter == b.end()) break;
      int k = *iter;
      auto iter2 = prev(a.lower_bound(k));
      found.emplace_back(*iter2, k);
      if (next(iter2) == a.end()) break;
      j = *next(iter2);
    }
    if (found.empty()) break;

    for (auto& [x, y] : found) {
      a.erase(x);
      b.erase(y);
      exists.erase(x);
      exists.erase(y);
    }
  }

  if (exists.empty()) return void(cout << "Bob\n");
  cout << (a.empty() ? "Bob\n" : "Alice\n");
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int tt = 1, tc = 1;
  cin >> tt;
  while (tt--) {
    cout << "Case #" << tc++ << ": ";
    solve();
  }
}
Editor is loading...
Leave a Comment