CF1859A.United We Stand
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Given an array a of length n, containing integers. And there are two initially empty arrays b and c. You need to add each element of array a to exactly one of the arrays b or c, in order to satisfy the following conditions:
- Both arrays b and c are non-empty. More formally, let lb be the length of array b, and lc be the length of array c. Then lb,lc≥1.
- For any two indices i and j (1≤i≤lb,1≤j≤lc), cj is not a divisor of bi.
Output the arrays b and c that can be obtained, or output −1 if they do not exist.
给定一个长度为 n 的整数数组 a。另有两个初始为空的数组 b 和 c。你需要将数组 a 中的每个元素恰好放入数组 b 或 c 中的一个,使得满足以下条件:
- 数组 b 和 c 均非空。更准确地说,设 lb 为数组 b 的长度,lc 为数组 c 的长度,则需满足 lb,lc≥1。
- 对任意下标 i 和 j(其中 1≤i≤lb,1≤j≤lc),cj 不能整除 bi。
输出一组满足条件的数组 b 和 c;若不存在这样的划分,则输出 −1。
输入格式
Each test consists of multiple test cases. The first line contains a single integer t (1≤t≤500) — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer n (2≤n≤100) — the length of array a.
The second line of each test case contains n integers a1,a2,…,an (1≤ai≤109) — the elements of array a.
每个测试包含多个测试用例。第一行包含一个整数 t(1≤t≤500),表示测试用例的数量。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(2≤n≤100),表示数组 a 的长度。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤109),表示数组 a 的元素。
输出格式
For each test case, output a single integer −1 if a solution does not exist.
Otherwise, in the first line, output two integers lb and lc — the lengths of arrays b and c respectively.
In the second line, output lb integers b1,b2,…,blb — the elements of array b.
In the third line, output lc integers c1,c2,…,clc — the elements of array c.
If there are multiple solutions, output any of them. You can output the elements of the arrays in any order.
对于每个测试用例,若解不存在,则输出单个整数 −1。
否则,在第一行输出两个整数 lb 和 lc —— 分别表示数组 b 和 c 的长度。
在第二行输出 lb 个整数 b1,b2,…,blb —— 表示数组 b 的元素。
在第三行输出 lc 个整数 c1,c2,…,clc —— 表示数组 c 的元素。
若存在多个解,输出任意一个即可。数组元素的顺序可以任意。
输入输出样例
输入#1
5 3 2 2 2 5 1 2 3 4 5 3 1 3 5 7 1 7 7 2 9 1 4 5 4 8 12 12 4
输出#1
-1 3 2 1 3 5 2 4 1 2 1 3 5 2 5 1 1 2 4 7 7 9 3 2 4 8 4 12 12
说明/提示
In the first test case, a solution does not exist.
In the second test case, we can obtain b=[1,3,5] and c=[2,4]. Then elements 2 and 4 do not divide elements 1,3 and 5.
In the fifth test case, we can obtain b=[4,8,4] and c=[12,12].
在第一个测试用例中,不存在解。
在第二个测试用例中,我们可以得到 b=[1,3,5] 和 c=[2,4]。此时,元素 2 和 4 均不能整除元素 1、3 和 5。
在第五个测试用例中,我们可以得到 b=[4,8,4] 和 c=[12,12]。
输入解题思路,AI测评打分。不知道怎么写?