luogu#P7940. 「Wdcfr-1」Alice Wins! (hard version)
「Wdcfr-1」Alice Wins! (hard version)
题目背景
题目描述
The difference between the versions is the limit of operations.
Alice is a cute girl who has a lot of dolls.
There are dolls playing rock-paper-scissors. They are divided into two teams: Team A and Team B. Each team contains dolls.
A total of rounds of the game will be played. In the -th round, the -th doll in Team A will play against the -th doll in Team B. If the doll in Team A wins, Team A will get point. If it loses, Team A will lose point. If it ties, Team A will not get points.
Alice knows all the dolls' choices in this game. To be precise, she uses two arrays and to represent the choices of the dolls in the two teams. means the choice of the -th doll in Team A, and means the choice of the -th doll in Team B. In this question, we use for rock, for scissors, and for paper.
Now for each team, Alice wants to change the choices of exact dolls to make the score of Team A as high as possible.
Find the maximum score of Team A and its construction method. If there are multiple answers print any of them (you still have to maximize the score of Team A).
输入格式
Each test contains multiple testcases. The first line contains an integer , the number of test cases.
For each test case, the first line contains one integer .
Then two lines follow, containing an array of length and an array of length , respectively.
输出格式
For each test case, output three lines.
The first line contains one integer, which is the maximize the score of Team A.
The second line contains an array of length , which represents the modified array. For integers to , if , then it means you have modified the hand shape of one player in Team A.
The third line contains an array of length , which represents the modified array. For integers to , if , then it means you have modified the hand shape of one player in Team B.
题目大意
AB 每队 人正在玩石头剪刀布。A 队第 个人出 ,B 队第 个人出 。编号相同的人会对战。若 A 队赢则加一分,平不得分,输扣一分。你必须恰好改变每队 个人的出拳方案,使得 A 队的得分最高。输出得分的最大值和任意一组构造方案。
本题中,我们用 代表石头, 代表剪刀, 代表布。
1
1
1 2
1 2
2
1 1
2 2
提示
Explanation
For the first test case, we can change to and to . Then Team A can get points. It can be proved that this is the maximum score that Team A can get.
Constraints
. The sum of of all test cases .