Logo
(追記) (追記ここまで)

31646번 - Test Tubes 서브태스크스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB127333228.070%

문제

Bessie has recently gotten into chemistry. At the moment, she has two different colors 1ドル$ and 2ドル$ of various liquids that don't mix well with one another. She has two test tubes of infinite capacity filled with $N$ $(1 \leq N \leq 10^5)$ units each of some mixture of liquids of these two colors. Because the liquids don’t mix, once they settled, they divided into layers of separate colors. Because of this, the two tubes can be viewed as strings $f_1f_2\ldots f_N$ and $s_1s_2\ldots s_N$ where $f_i$ represents the color of the liquid that is $i$ units from the bottom of the first tube, and $s_i$ represents the color of the liquid that is $i$ units from the bottom of the second tube. It is guaranteed that there is at least one unit of each color of liquid.

Bessie wants to separate these liquids so that each test tube contains all units of one color of liquid. She has a third empty beaker of infinite capacity to help her in this task. When Bessie makes a "pour", she moves all liquid of color $i$ at the top of one test tube or beaker into another.

Determine the minimum number of pours to separate all the liquid into the two test tubes, and the series of moves needed to do so. It does not matter which test tube ends up with which color, but the beaker must be empty..

There will be $T$ (1ドル \leq T \leq 10$) test cases, with a parameter $P$ for each test case.

Suppose the minimum number of pours to separate the liquids into the original tubes is $M$.

  • If $P=1,ドル you will receive credit if you print only $M$.
  • If $P=2,ドル you will receive credit if you print an integer $A$ such that $M \leq A \leq M+5,ドル followed by $A$ lines that construct a solution with that number of moves. Each line should contain the source and the destination tube (1ドル,ドル 2ドル,ドル or 3ドル$ for the beaker). The source tube must be nonempty before the move and a tube may not be poured into itself.
  • If $P=3,ドル you will receive credit if you print $M,ドル followed by a valid construction using that number of moves.

입력

The first line contains $T,ドル the. number of test cases. For each test case, the next line contains $N$ and $P$ representing the amount each test tube is initially filled to, and the query type. The following line contains $f_1f_2f_3\ldots f_N$ representing the first test tube. $f_i \in \{ 1,2 \}$ and $f_1$ represents the bottom of the test tube. The subsequent line contains $s_1s_2s_3\ldots s_N$ representing the second test tube. $s_i \in \{ 1,2 \}$ and $s_1$ represents the bottom of the test tube.

It is guaranteed that there will be at least one 1ドル$ and one 2ドル$ across both input strings.

출력

For each test case, you will print a single number representing the minimum pours to separate the liquid in the test tubes. Depending on the query type, you may also need to provide a valid construction.

제한

서브태스크

번호배점제한
120

$P=1$

220

$P=2$

360

No additional constraints.

예제 입력 1

6
4 1
1221
2211
4 2
1221
2211
4 3
1221
2211
6 3
222222
111112
4 3
1121
1222
4 2
1121
1222

예제 출력 1

4
4
1 2
1 3
2 1
3 2
4
1 2
1 3
2 1
3 2
1
2 1
5
2 3
1 2
1 3
1 2
3 1
6
2 3
1 2
1 3
1 2
2 1
3 2

In the first three test cases, the minimum number of pours to separate the tubes is 4ドル$. We can see how the following moves separate the test tubes:

Initial state:

1: 1221
2: 2211
3: 

After the move "1 2":

1: 122
2: 22111
3: 

After the move "1 3":

1: 1
2: 22111
3: 22

After the move "2 1":

1: 1111
2: 22
3: 22

After the move "3 2":

1: 1111
2: 2222
3:

In the last test case, the minimum amount of pours is 5ドル$. However, since $P=2,ドル the given construction with 6ドル$ moves is valid since it is within 5ドル$ pours from the optimal answer.

힌트

출처

Olympiad > USA Computing Olympiad > 2023-2024 Season > USACO 2024 February Contest > Silver 2번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /