fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. const int Mod=998244353;
  5.  
  6.  
  7. void solve() {
  8. int n;
  9. cin >> n;
  10. string s;
  11. cin >> s;
  12. vector<int> A,B;
  13. if(n==2){
  14. if(s[0]=='A') cout << "Alice\n";
  15. else cout << "Bob\n";
  16. return;
  17. }
  18. for(int i=0;i<n;i++){
  19. if(s[i]=='A') A.push_back(i+1);
  20. else B.push_back(i+1);
  21. }
  22. for(int i=0;i<A.size();i++){
  23. bool flag=true;
  24. for(int j=0;j<B.size();j++){
  25. if(B[j]>A[i]){
  26. if(B[j]==n && A[i]==1) continue;
  27. flag=false;
  28. }
  29. if(A[i]==n && B[j]==1) flag=false;
  30. }
  31. if(flag) {cout << "Alice\n";return;}
  32. }
  33. cout << "Bob\n";
  34. }
  35.  
  36. int main(){
  37. ios::sync_with_stdio(false);
  38. cin.tie(nullptr);
  39.  
  40. int t;
  41. cin >> t;
  42. while (t--) solve();
  43.  
  44.  
  45. return 0;
  46. }
  47.  
Success #stdin #stdout 0s 5316KB
stdin
8
2
AB
2
BA
4
ABAB
4
BABA
3
BAA
5
AAAAB
5
BAAAB
6
BBBAAA
stdout
Alice
Bob
Bob
Bob
Alice
Alice
Bob
Alice