RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
USACO0535

Circular Barn

Silver II 실버 II
난이도
2s
시간 제한
256MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

Farmer John and his archnemesis Farmer Nhoj are playing a game in a circular
barn. There are \(N\) (\(1 \leq N \leq 10^5\)) rooms in the barn, and the \(i\)th room
initially contains \(a_i\) cows (\(1 \leq a_i \leq 5\cdot 10^6\)). The game is
played as follows:

  • Both farmers will always be in the same room. After entering a room, each farmer takes exactly one turn, with Farmer John going first. Both farmers initially enter room \(1\).
  • If there are zero cows in the current room, then the farmer to go loses. Otherwise, the farmer to go chooses an integer \(P\), where \(P\) must either be \(1\) or a prime number at most the number of cows in the current room, and removes \(P\) cows from the current room.
  • After both farmers have taken turns, both farmers move to the next room in the circular barn. That is, if the farmers are in room \(i\), then they move to room \(i+1\), unless they are in room \(N\), in which case they move to room \(1\).

Determine the farmer that wins the game if both farmers play optimally.

Problem credits: Chongtian Ma, Jesse Choe, and Yuval Vaknin

제약

SCORING

  • Inputs 2-4 satisfy \(N=1\).
  • Inputs 1, 2, and 5-7 satisfy \(a_i\le 1000\).
  • Inputs 8-20 satisfy no additional constraints.

Problem credits: Chongtian Ma, Jesse Choe, and Yuval Vaknin

입력 형식

The input contains \(T\) test cases. The first line contains \(T\)
(\(1 \leq T \leq 1000\)). Each of the \(T\) test cases follow.

Each test case starts with a line containing \(N\), followed by a line containing
\(a_1,\dots,a_N\).

It is guaranteed that the sum of all \(N\) is at most
\(2\cdot 10^5\).

출력 형식

For each test case, output the farmer that wins the game, either "Farmer John"
or "Farmer Nhoj."

예제 1
입력
5
1
4
1
9
2
2 3
2
7 10
3
4 9 4
출력
Farmer Nhoj
Farmer John
Farmer John
Farmer John
Farmer Nhoj
설명

For the first test case, Farmer John can remove \(1\), \(2\), or \(3\) cows from the
first room. Whichever number he removes, Nhoj can remove the remaining cow(s),
forcing FJ to lose when they circle back to the first room.

For the second test case, FJ can remove \(5\) cows, forcing Nhoj to work with only
\(4\) cows remaining. Now, Nhoj can either remove \(1\), \(2\), or \(3\) cows. This is
now similar to the first test case.

For the third and fourth test cases, FJ can immediately remove all the cows from
the first room, forcing Nhoj to lose.

For the fifth test case, FJ can remove \(1\), \(2\), or \(3\), cows from the first
room, and Nhoj can remove the rest right after. When they circle back around to
the first room, FJ will lose.

문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2022-2023 > December > Silver

태그

평가 및 의견

Circular Barn

개요
출제자 난이도 Silver II 실버 II 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Circular Barn

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8