| ps | |
|---|---|
| 링크 | acmicpc.net/… |
| 출처 | BOJ |
| 문제 번호 | 3754 |
| 문제명 | John |
| 레벨 | 플래티넘 2 |
| 분류 |
게임 이론 |
| 시간복잡도 | O(T*n) |
| 인풋사이즈 | T<=474, n<=47 |
| 사용한 언어 | Python 3.11 |
| 제출기록 | 34136KB / 76ms |
| 최고기록 | 40ms |
| 해결날짜 | 2023/07/22 |
"""Solution code for "BOJ 3754. John".
- Problem link: https://www.acmicpc.net/problem/3754
- Solution link: http://www.teferi.net/ps/problems/boj/3754
Tags: [game theory]
"""
import functools
import operator
import sys
def main():
T = int(sys.stdin.readline())
for _ in range(T):
N = int(sys.stdin.readline())
A = [int(x) for x in sys.stdin.readline().split()]
if max(A) == 1:
print('John' if N % 2 == 0 else 'Brother')
else:
grundy = functools.reduce(operator.xor, A)
print('John' if grundy != 0 else 'Brother')
if __name__ == '__main__':
main()