fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. using ll = long long;
  4.  
  5. int main() {
  6. ios::sync_with_stdio(false);
  7. cin.tie(nullptr);
  8.  
  9. int T;
  10. cin >> T;
  11. const int MAXB = 31; // Ai ≤ 1e9 이므로 0..30 비트
  12.  
  13. while (T--) {
  14. int N;
  15. cin >> N;
  16. vector<ll> A(N);
  17. for (int i = 0; i < N; i++) {
  18. cin >> A[i];
  19. }
  20.  
  21. // 각 비트별 등장 개수
  22. vector<int> cnt(MAXB, 0);
  23. for (int i = 0; i < N; i++) {
  24. ll x = A[i];
  25. for (int b = 0; b < MAXB; b++) {
  26. if (x & (1LL << b)) {
  27. cnt[b]++;
  28. }
  29. }
  30. }
  31.  
  32. ll total_xor = 0;
  33. for (int i = 0; i < N; i++) {
  34. ll forced = 0;
  35. ll x = A[i];
  36. for (int b = 0; b < MAXB; b++) {
  37. if ( (x & (1LL << b)) && cnt[b] == 1 ) {
  38. // 이 비트는 오직 이 더미에만 존재하므로 forced로 유지
  39. forced |= (1LL << b);
  40. }
  41. }
  42. ll free_part = A[i] - forced;
  43. total_xor ^= free_part;
  44. }
  45.  
  46. if (total_xor != 0) {
  47. cout << "Alice\n";
  48. } else {
  49. cout << "Bob\n";
  50. }
  51. }
  52.  
  53. return 0;
  54. }
Success #stdin #stdout 0.01s 5324KB
stdin
4
3
3 4 6
3
7 7 7
3
9 3 5
10
1 9 1 3 7 9 10 9 7 3
stdout
Bob
Alice
Alice
Alice