A16336 | Two Out of Three
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given an array $a_1, a_2, \ldots, a_n$ . You need to find an array $b_1, b_2, \ldots, b_n$ consisting of numbers $1$ , $2$ , $3$ such that exactly two out of the following three conditions are satisfied:
1. There exist indices $1 \leq i, j \leq n$ such that $a_i = a_j$ , $b_i = 1$ , $b_j = 2$ .
2. There exist indices $1 \leq i, j \leq n$ such that $a_i = a_j$ , $b_i = 1$ , $b_j = 3$ .
3. There exist indices $1 \leq i, j \leq n$ such that $a_i = a_j$ , $b_i = 2$ , $b_j = 3$ .
If such an array does not exist, you should report it.
1. There exist indices $1 \leq i, j \leq n$ such that $a_i = a_j$ , $b_i = 1$ , $b_j = 2$ .
2. There exist indices $1 \leq i, j \leq n$ such that $a_i = a_j$ , $b_i = 1$ , $b_j = 3$ .
3. There exist indices $1 \leq i, j \leq n$ such that $a_i = a_j$ , $b_i = 2$ , $b_j = 3$ .
If such an array does not exist, you should report it.
输入格式
Each test contains multiple test cases. The first line contains a single integer $t$ $(1 \leq t \leq 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 \leq n \leq 100)$ — the length of the array $a$ .
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \leq a_i \leq 100)$ — the elements of the array $a$ .
The first line of each test case contains an integer $n$ $(1 \leq n \leq 100)$ — the length of the array $a$ .
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \leq a_i \leq 100)$ — the elements of the array $a$ .
输出格式
For each test case, print -1 if there is no solution. Otherwise, print $b_1, b_2, \ldots, b_n$ — 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
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$ : $a_i = a_j$ , $b_i = 1$ , and $b_j = 2$ . It also satisfies condition $2$ because for $i = 6$ , $j = 3$ : $a_i = a_j$ , $b_i = 1$ , and $b_j = 3$ . However, it does not satisfy condition $3$ . In total, exactly two out of three conditions are satisfied.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted