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

COW Splits

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

의견: 0

설명

Bessie is given a positive integer \(N\) and a string \(S\) of length \(3N\) which is
generated by concatenating \(N\) strings of length \(3\), each of which is a cyclic
shift of "COW". In other words, each string will be "COW", "OWC", or "WCO".

String \(X\) is a square string if and only if there exists a string \(Y\)
such that \(X = Y + Y\) where \(+\) represents string concatenation. For example,
"COWCOW" and "CC" are examples of square strings but "COWO" and "OC" are not.

In a single operation, Bessie can remove any subsequence \(T\) from \(S\)
where \(T\) is a square string. A subsequence of a string is a string which can be
obtained by removing several (possibly zero) characters from the original
string.

Your job is to help Bessie determine whether it is possible to transform \(S\)
into an empty string. Additionally, if it is possible, then you must provide a
way to do so.

Bessie is also given a parameter \(k\) which is either \(0\) or \(1\). Let \(M\) be the
number of operations in your construction.

  • If \(k = 0\), then \(M\) must equal the minimum possible number of operations.
  • If \(k = 1\), then \(M\) can be up to one plus the minimum possible number of operations

Problem credits: Aakash Gokhale

제약

SCORING

  • Inputs 3-4: \(T \le 10, N \le 6, k = 0\)
  • Inputs 5-6: \(k = 1\)
  • Inputs 7-14: \(k = 0\)

Problem credits: Aakash Gokhale

입력 형식

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 10^5\)).

The second line of each test case has \(S\).

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

출력 형식

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

If it is impossible to transform \(S\) into an empty string, print \(-1\) on a
single line.

Otherwise, on the first line print \(M\) -- the number of operations in your
construction. On the second line, print \(3N\) space-separated integers. The
\(i\)th integer \(x\) indicates that the \(i\)th letter of \(S\) was deleted as part of
the \(x\)th subsequence (\(1 \le x \le M\)).

예제 1
입력
3 1
3
COWOWCWCO
4
WCOCOWWCOCOW
6
COWCOWOWCOWCOWCOWC
출력
-1
1
1 1 1 1 1 1 1 1 1 1 1 1
3
3 3 2 3 3 2 1 1 1 1 1 1 1 1 1 1 1 1
설명

For the last test, the optimal number of operations is two, so any valid
construction with either \(M=2\) or \(M=3\) would be accepted.

For \(M=3\), here is a possible construction:

  1. In the first operation, remove the last twelve characters. Now we're left with COWCOW.
  2. In the second operation, remove the subsequence WW. Now we're left with COCO.
  3. In the last operation, remove all remaining characters.
예제 2
입력
3 0
3
COWOWCWCO
4
WCOCOWWCOCOW
6
COWCOWOWCOWCOWCOWC
출력
-1
1
1 1 1 1 1 1 1 1 1 1 1 1
2
1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2
문제 정보

riseoj 작성

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

태그

평가 및 의견

COW Splits

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

Log in to rate problems.

개별 의견

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

풀이 제출

COW Splits

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