CF1894B.Two Out of Three
入门
通过率:0%
时间限制:3.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an array a1,a2,…,an. You need to find an array b1,b2,…,bn consisting of numbers 1, 2, 3 such that exactly two out of the following three conditions are satisfied:
- There exist indices 1≤i,j≤n such that ai=aj, bi=1, bj=2.
- There exist indices 1≤i,j≤n such that ai=aj, bi=1, bj=3.
- There exist indices 1≤i,j≤n such that ai=aj, bi=2, bj=3.
If such an array does not exist, you should report it.
给你一个数组 a1,a2,…,an。你需要构造一个由数字 1、2、3 组成的数组 b1,b2,…,bn,使得以下三个条件中恰好有两个成立:
- 存在下标 1≤i,j≤n,满足 ai=aj,bi=1,bj=2。
- 存在下标 1≤i,j≤n,满足 ai=aj,bi=1,bj=3。
- 存在下标 1≤i,j≤n,满足 ai=aj,bi=2,bj=3。
如果不存在满足要求的数组 b,则应报告无解。
输入格式
Each test contains multiple test cases. The first line contains a single integer t (1≤t≤500) — the number of test cases. Each test case is described as follows.
The first line of each test case contains an integer n (1≤n≤100) — the length of the array a.
The second line of each test case contains n integers a1,a2,…,an (1≤ai≤100) — the elements of the array a.
每个测试包含多个测试用例。第一行包含一个整数 t(1≤t≤500)—— 测试用例的数量。每个测试用例的描述如下:
每个测试用例的第一行包含一个整数 n(1≤n≤100)—— 数组 a 的长度。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤100)—— 数组 a 的元素。
输出格式
For each test case, print -1 if there is no solution. Otherwise, print b1,b2,…,bn — an array consisting of numbers 1, 2, 3 that satisfies exactly two out of three conditions. If there are multiple possible answers, you can print any of them.
对于每个测试用例,若无解,则输出 -1。否则,输出 b1,b2,…,bn —— 一个由数字 1、2、3 组成的数组,该数组恰好满足以下三个条件中的两个。若存在多个可能的答案,输出任意一个即可。
输入输出样例
输入#1
9 6 1 2 3 2 2 3 7 7 7 7 7 7 7 7 4 1 1 2 2 7 1 2 3 4 5 6 7 5 2 3 3 3 2 3 1 2 1 9 1 1 1 7 7 7 9 9 9 1 1 18 93 84 50 21 88 52 16 50 63 1 30 85 29 67 63 58 37 69
输出#1
1 2 3 1 1 1 -1 3 2 2 1 -1 2 1 2 1 3 -1 1 1 2 2 1 2 2 3 3 -1 3 2 1 3 3 3 3 2 2 1 1 2 3 1 3 1 1 2
说明/提示
In the first test case, b=[1,2,3,1,1,1] satisfies condition 1 because for i=4, j=2: ai=aj, bi=1, and bj=2. It also satisfies condition 2 because for i=6, j=3: ai=aj, bi=1, and bj=3. However, it does not satisfy condition 3. In total, exactly two out of three conditions are satisfied.
在第一个测试用例中,b=[1,2,3,1,1,1] 满足条件 1,因为当 i=4、j=2 时:ai=aj,bi=1,且 bj=2。它也满足条件 2,因为当 i=6、j=3 时:ai=aj,bi=1,且 bj=3。然而,它不满足条件 3。总计,三个条件中恰好有两个被满足。
输入解题思路,AI测评打分。不知道怎么写?