CF1859A.United We Stand

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Given an array aa of length nn, containing integers. And there are two initially empty arrays bb and cc. You need to add each element of array aa to exactly one of the arrays bb or cc, in order to satisfy the following conditions:

  • Both arrays bb and cc are non-empty. More formally, let lbl_b be the length of array bb, and lcl_c be the length of array cc. Then lb,lc≥1l_b, l_c \ge 1.
  • For any two indices ii and jj (1≤i≤lb,1≤j≤lc1 \le i \le l_b, 1 \le j \le l_c), cjc_j is not a divisor of bib_i.

Output the arrays bb and cc that can be obtained, or output −1-1 if they do not exist.

给定一个长度为 nn 的整数数组 aa。另有两个初始为空的数组 bb 和 cc。你需要将数组 aa 中的每个元素恰好放入数组 bb 或 cc 中的一个,使得满足以下条件:

  • 数组 bb 和 cc 均非空。更准确地说,设 lbl_b 为数组 bb 的长度,lcl_c 为数组 cc 的长度,则需满足 lb,lc≥1l_b, l_c \ge 1。
  • 对任意下标 ii 和 jj(其中 1≤i≤lb1 \le i \le l_b,1≤j≤lc1 \le j \le l_c),cjc_j 不能整除 bib_i。

输出一组满足条件的数组 bb 和 cc;若不存在这样的划分,则输出 −1-1。

输入格式

Each test consists of multiple test cases. The first line contains a single integer tt (1≤t≤5001 \le t \le 500) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer nn (2≤n≤1002 \le n \le 100) — the length of array aa.

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1091 \le a_i \le 10^9) — the elements of array aa.

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤5001 \le t \le 500),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(2≤n≤1002 \le n \le 100),表示数组 aa 的长度。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1091 \le a_i \le 10^9),表示数组 aa 的元素。

输出格式

For each test case, output a single integer −1-1 if a solution does not exist.

Otherwise, in the first line, output two integers lbl_b and lcl_c — the lengths of arrays bb and cc respectively.

In the second line, output lbl_b integers b1,b2,…,blbb_1, b_2, \ldots, b_{l_b} — the elements of array bb.

In the third line, output lcl_c integers c1,c2,…,clcc_1, c_2, \ldots, c_{l_c} — the elements of array cc.

If there are multiple solutions, output any of them. You can output the elements of the arrays in any order.

对于每个测试用例,若解不存在,则输出单个整数 −1-1。

否则,在第一行输出两个整数 lbl_b 和 lcl_c —— 分别表示数组 bb 和 cc 的长度。

在第二行输出 lbl_b 个整数 b1,b2,…,blbb_1, b_2, \ldots, b_{l_b} —— 表示数组 bb 的元素。

在第三行输出 lcl_c 个整数 c1,c2,…,clcc_1, c_2, \ldots, c_{l_c} —— 表示数组 cc 的元素。

若存在多个解,输出任意一个即可。数组元素的顺序可以任意。

输入输出样例

  • 输入#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]b = [1, 3, 5] and c=[2,4]c = [2, 4]. Then elements 22 and 44 do not divide elements 1,31, 3 and 55.

In the fifth test case, we can obtain b=[4,8,4]b = [4, 8, 4] and c=[12,12]c = [12, 12].

在第一个测试用例中,不存在解。

在第二个测试用例中,我们可以得到 b=[1,3,5]b = [1, 3, 5] 和 c=[2,4]c = [2, 4]。此时,元素 22 和 44 均不能整除元素 11、33 和 55。

在第五个测试用例中,我们可以得到 b=[4,8,4]b = [4, 8, 4] 和 c=[12,12]c = [12, 12]。

输入解题思路,AI测评打分。不知道怎么写?

首页