#P12985. [GCJ 2022 #1A] Equal Sum

    ID: 12782 Type: RemoteJudge 5000ms 1024MiB Tried: 0 Accepted: 0 Difficulty: 5 Uploaded By: Tags>数学贪心2022交互题Special Judge进制构造Google Code Jam

[GCJ 2022 #1A] Equal Sum

题目描述

You are given a set of distinct integers. You need to separate them into two non-empty subsets such that each element belongs to exactly one of them and the sum of all elements of each subset is the same.

An anonymous tip told us that the problem above was unlikely to be solved in polynomial time (or something like that), so we decided to change it. Now you get to decide what half of the integers are!

This is an interactive problem with three phases. In phase 1, you choose N\mathbf{N} distinct integers. In phase 2, you are given another N\mathbf{N} integers that are distinct from each other and from the ones you chose in phase 1. In phase 3, you have to partition those 2N2\mathbf{N} integers into two subsets, both of which sum to the same amount. All 2N2\mathbf{N} integers are to be between 1 and 10910^9, inclusive, and it is guaranteed that they sum up to an even number.

Interactive Protocol

This is an interactive problem.

Initially, your program should read a single line containing an integer, T\mathbf{T}, the number of test cases. Then, T\mathbf{T} test cases must be processed.

For each test case, your program must first read a line containing a single integer N\mathbf{N}. Then, it must output a line containing N\mathbf{N} distinct integers A1,A2,,ANA_1, A_2, \ldots, A_{\mathbf{N}}. Each of these integers must be between 1 and 10910^9, inclusive. After that, your program must read a line containing N\mathbf{N} additional integers B1,B2,,BNB_1, B_2, \ldots, B_{\mathbf{N}}. Finally, your program must output a line containing between 1 and 2N12\mathbf{N}-1 integers from among $A_1, A_2, \ldots, A_{\mathbf{N}}, B_1, B_2, \ldots, B_{\mathbf{N}}$: the ones chosen to be part of the first subset. The integers from AA and BB that you do not output are considered to be part of the other subset.

The next test case starts immediately if there is one. If this was the last test case, the judge will expect no more output and will send no further input to your program. In addition, all T\mathbf{T} test cases are always processed, regardless of whether the final output from your program is correct or not.

Note: It can be shown that given the limits for this problem, there exists a sequence A1,A2,,ANA_1, A_2, \ldots, A_{\mathbf{N}} such that any sequence B1,B2,,BNB_1, B_2, \ldots, B_{\mathbf{N}} results in a set of 2N2\mathbf{N} integers that can be separated into two subsets with equal sums.

If the judge receives an invalidly formatted or invalid line (like outputting an unexpected number of integers, or integers out of range, or repeated integers in a line) from your program at any moment, the judge will print a single number -1 and will not print any further output. If your program continues to wait for the judge after receiving a -1, your program will time out, resulting in a Time Limit Exceeded error. Notice that it is your responsibility to have your program exit in time to receive a Wrong Answer judgment instead of a Time Limit Exceeded error. As usual, if the memory limit is exceeded, or your program gets a runtime error, you will receive the appropriate judgment.

输入格式

See Interactive Protocol.

输出格式

See Interactive Protocol.

2
3

10 4 9

3

10 8 12


5 1 3

1 10 5

5 2 3

12 8

提示

Sample Explanation

In the sample interaction above, the solution gets all cases right and would receive a correct verdict. Notice that the value for N\mathbf{N} does not conform to the limits for the Test Set and is used to simplify the example only. Notice that the judge could have given the solution the integers {2,7,100}\{2, 7, 100\} for the first case, making it impossible for the solution to find a valid partition into subsets of equal sum.

You can use this testing tool to test locally or on our platform. To test locally, you will need to run the tool in parallel with your code; you can use our interactive runner for that.

Instructions for the testing tool are included in comments within the tool. We encourage you to add your own test cases. Please be advised that although the testing tool is intended to simulate the judging system, it is NOT the real judging system and might behave differently.

Limits

Test Set 1 (Visible Verdict)

  • 1T1001 \leq \mathbf{T} \leq 100.
  • N=100\mathbf{N} = 100.
  • 1Bi1091 \leq \mathbf{B}_i \leq 10^9, for all ii.
  • BiAj\mathbf{B}_i \neq A_j, for all i,ji, j.
  • BiBj\mathbf{B}_i \neq \mathbf{B}_j, for all iji \neq j.
  • For each test case, the judge will choose the Bi\mathbf{B}_is such that the sum of all 2N2\mathbf{N} integers is even.