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

It's Mooin' Time IV

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

의견: 0

설명

Bessie has a computer with a keyboard that only has two letters, M and O.

Bessie wants to type her favorite moo \(S\) consisting of \(N\) letters, each of
which is either an M or an O. However, her computer has been hit with a virus.
Every time she tries to type the letter O, every letter that she has typed so
far flips, either from M to O or from O to M, before the O appears.

Is it possible for Bessie to type out her favorite moo?

Additionally, Bessie is given a parameter \(k\) which is either \(0\) or \(1\).

  • If \(k = 0\), then Bessie only needs to determine whether it is possible to type out her favorite moo.
  • If \(k = 1\), then Bessie also needs to give an example of a sequence of keystrokes to type so she can type out her favorite moo.

Problem credits: Nick Wu

제약

SCORING

  • Inputs 3-4: \(k=0\).
  • Inputs 5-6: \(k=1, T \le 10^3, N \le 10\).
  • Inputs 7-9: \(k=1, T \le 10, N \le 1000\).
  • Inputs 10-16: \(k=1\).

Problem credits: Nick Wu

입력 형식

The first line contains \(T\), the number of independent test cases
(\(1\le T\le 10^4\)) and \(k\) (\(0 \le k \le 1\)).

The first line of each test case has \(N\) (\(1 \le N \le 2 \cdot 10^5\)).

The second line of each test case has \(S\). It is guaranteed that no characters
will appear in \(S\) besides \(\texttt{M}\) and \(\texttt{O}\).

The sum of \(N\) across all test cases will not exceed \(4 \cdot 10^5\).

출력 형식

For each test case, output either one or two lines using the following
procedure.

If it is impossible for Bessie to type out \(S\), print \(\texttt{NO}\)
on a single line.

Otherwise, on the first line print \(\texttt{YES}\). Furthermore, if \(k=1\), on the
second line, print a string of length \(N\), the characters in order that Bessie
needs to type in order to type out her favorite moo. If there are multiple such
strings, any will be accepted.

예제 1
입력
2 0
3
MOO
5
OOMOO
출력
YES
YES
예제 2
입력
2 1
3
MOO
5
OOMOO
출력
YES
OMO
YES
MOOMO
설명

As Bessie types out \(\texttt{MOOMO}\), this is how the letters change:

  1. Before typing the first \(\texttt{M}\), Bessie has an empty string. Afterwards, she has the string \(\texttt{M}\).
  2. After typing the first \(\texttt{O}\), the \(\texttt{M}\) flips to \(\texttt{O}\), and then the \(\texttt{O}\) is appended to form \(\texttt{OO}\).
  3. After typing the second \(\texttt{O}\), the \(\texttt{OO}\) flips to \(\texttt{MM}\), and then the \(\texttt{O}\) is appended to form \(\texttt{MMO}\).
  4. After typing the second \(\texttt{M}\), Bessie has the string \(\texttt{MMOM}\).
  5. After typing the last \(\texttt{O}\), the string \(\texttt{MMOM}\) flips to \(\texttt{OOMO}\), and then the \(\texttt{O}\) is appended to form \(\texttt{OOMOO}\), as desired.
문제 정보

riseoj 작성

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

태그

평가 및 의견

It's Mooin' Time IV

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

Log in to rate problems.

개별 의견

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

풀이 제출

It's Mooin' Time IV

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