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. if (!(cin >> T)) return 0;
  11. while (T--) {
  12. int N;
  13. cin >> N;
  14. vector<ll> A(N);
  15. for (int i = 0; i < N; ++i) cin >> A[i];
  16.  
  17. // 비트별 등장 횟수 (0..30)
  18. const int B = 31; // 0..30 포함
  19. vector<int> cnt(B, 0);
  20. for (int i = 0; i < N; ++i) {
  21. for (int b = 0; b < B; ++b) {
  22. if ( (A[i] >> b) & 1LL ) cnt[b]++;
  23. }
  24. }
  25.  
  26. ll xr = 0;
  27. for (int i = 0; i < N; ++i) {
  28. ll forced = 0;
  29. for (int b = 0; b < B; ++b) {
  30. if ( ((A[i] >> b) & 1LL) && cnt[b] == 1 ) {
  31. forced |= (1LL << b);
  32. }
  33. }
  34. ll d = A[i] - forced; // Nim-크기
  35. xr ^= d;
  36. }
  37.  
  38. if (xr != 0) cout << "Alice\n";
  39. else cout << "Bob\n";
  40. }
  41. return 0;
  42. }
Success #stdin #stdout 0.01s 5288KB
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