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

Cow-libi 2

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

의견: 0

설명

Farmer John and Farmer Nhoj have taken their respective cows to sit around a
campfire in hopes of settling their personal differences. In total, there are
\(N\) (\(2 \leq N \leq 10^5\)) cows sitting in a circular formation. When the
farmers are ready to take their cows back to their farms, they realize one
crucial mistake: since all the cows look the same and are mixed up, they are
unable to identify which cows belong to which farmer!

Then the \(N\) cows are organized into one straight line to be interrogated by the
two farmers.
**
Because of the confusion, the order of the cows in the line, from \(1\) to \(N\),
might not correspond to their circular order around the campfire.
**

But the cows want to play a game. Instead of answering directly which farmer
they belong to, they say which farmer the cows ** adjacent to them in the
original circle ** belong to. Additionally, it is known that Farmer Nhoj's
cows always lie but Farmer John raised his cows well and they will always tell
the truth.

Given the statements of the cows, is it possible to assign each cow to either
Farmer John or Farmer Nhoj such that the statements of the cows assigned to
Farmer John are all true, and the statements of the cows assigned to Farmer Nhoj
are all false?

Problem credits: Chongtian Ma

제약

SCORING

  • Input 3: \(C=0\) and \(N\le 10\)
  • Input 4: \(C=1\) and \(N\le 10\)
  • Inputs 5-8: \(C=0\)
  • Inputs 9-12: \(C=1\)

Problem credits: Chongtian Ma

입력 형식

The first line contains \(T\) (\(1 \leq T \leq 1000\)), the number of independent
test cases, and an integer \(C\in \{0,1\}\) (whether to output a construction or
not).

The first line of each test case contains \(N\).

The following line contains a string of length \(N\) containing characters J or N.
The \(i\)'th character is J if cow \(i\) claims the cow to their ** left ** in
the circle belongs to Farmer John, or Farmer Nhoj otherwise.

The following line contains a string of length \(N\) containing characters J or N.
The \(i\)'th character is J if cow \(i\) claims the cow to their ** right ** in
the circle belongs to Farmer John, or Farmer Nhoj otherwise.

It is guaranteed that the sum of \(N\) over all tests does not exceed
\(5 \cdot 10^5\).

출력 형식

For each test case, output YES or NO.

Additionally, if \(C=1\) and the answer is YES, output two more lines describing
your construction:

The first line should contain a permutation \(p_1, p_2, \dots, p_N\) of
\(1\dots N\), representing the circular order of the cows around the campfire,
where cow \(p_i\) is to the left of cow \(p_{i+1}\) for \(i\) in \(1 \dots N - 1\), and
cow \(p_N\) is to the left of cow \(p_1\).

The second line should contain a string \(b_1b_2\dots b_N\) consisting only of Js
and Ns, meaning that cow \(p_i\) belongs to Farmer John if \(b_i\) is J, or Farmer
Nhoj otherwise.

Any valid construction will be accepted.

예제 1
입력
6 0
3
JJJ
JJJ
4
JJNJ
NJJJ
6
NJNJNJ
JNNJNJ
4
NNNN
NNNN
3
NNN
NNN
5
JJNNJ
NJNJJ
출력
YES
NO
NO
YES
NO
YES
예제 2
입력
6 1
3
JJJ
JJJ
4
JJNJ
NJJJ
6
NJNJNJ
JNNJNJ
4
NNNN
NNNN
3
NNN
NNN
5
JJNNJ
NJNJJ
출력
YES
1 2 3
JJJ
NO
NO
YES
1 2 3 4
NJNJ
NO
YES
4 5 2 1 3
JJJJN
설명

Consider the output for the sixth test case. Cows 1, 2, 4, 5 belong to Farmer
John, and Cow 3 belongs to Farmer Nhoj.

The cows will then behave as follows:

  • Cow 1's left and right neighbours are Cow 2 and Cow 3, respectively. Cow 1 says that Cow 2 belongs to Farmer John, and Cow 3 belongs to Farmer Nhoj.
  • Cow 2's left and right neighbours are Cow 5 and Cow 1, respectively. Cow 2 says that both cows belong to Farmer John.
  • Cow 3's left and right neighbours are Cow 1 and Cow 4, respectively. Cow 3 (dishonestly) says that both cows belong to Farmer Nhoj.
  • Cow 4's left and right neighbours are Cow 3 and Cow 5, respectively. Cow 4 says that Cow 3 belongs to Farmer Nhoj, and Cow 5 belongs to Farmer John.
  • Cow 5's left and right neighbours are Cow 4 and Cow 2, respectively. Cow 5 says that both cows belong to Farmer John.

All these claims are consistent with the input.

문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2025-2026 > Second Contest > Silver

태그

평가 및 의견

Cow-libi 2

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

Log in to rate problems.

개별 의견

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

풀이 제출

Cow-libi 2

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