A15252 | Too Many Constraints
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are asked to build an array $a$ , consisting of $n$ integers, each element should be from $1$ to $k$ .
The array should be non-decreasing ( $a_i \le a_{i+1}$ for all $i$ from $1$ to $n-1$ ).
You are also given additional constraints on it. Each constraint is of one of three following types:
- $1~i~x$ : $a_i$ should not be equal to $x$ ;
- $2~i~j~x$ : $a_i + a_j$ should be less than or equal to $x$ ;
- $3~i~j~x$ : $a_i + a_j$ should be greater than or equal to $x$ .
Build any non-decreasing array that satisfies all constraints or report that no such array exists.
The array should be non-decreasing ( $a_i \le a_{i+1}$ for all $i$ from $1$ to $n-1$ ).
You are also given additional constraints on it. Each constraint is of one of three following types:
- $1~i~x$ : $a_i$ should not be equal to $x$ ;
- $2~i~j~x$ : $a_i + a_j$ should be less than or equal to $x$ ;
- $3~i~j~x$ : $a_i + a_j$ should be greater than or equal to $x$ .
Build any non-decreasing array that satisfies all constraints or report that no such array exists.
输入格式
The first line contains a single integer $t$ ( $1 \le t \le 10^4$ ) — the number of testcases.
The first line of each testcase contains three integers $n, m$ and $k$ ( $2 \le n \le 2 \cdot 10^4$ ; $0 \le m \le 2 \cdot 10^4$ ; $2 \le k \le 10$ ).
The $i$ -th of the next $m$ lines contains a description of a constraint. Each constraint is of one of three following types:
- $1~i~x$ ( $1 \le i \le n$ ; $1 \le x \le k$ ): $a_i$ should not be equal to $x$ ;
- $2~i~j~x$ ( $1 \le i < j \le n$ ; $2 \le x \le 2 \cdot k$ ): $a_i + a_j$ should be less than or equal to $x$ ;
- $3~i~j~x$ ( $1 \le i < j \le n$ ; $2 \le x \le 2 \cdot k$ ): $a_i + a_j$ should be greater than or equal to $x$ .
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^4$ . The sum of $m$ over all testcases doesn't exceed $2 \cdot 10^4$ .
The first line of each testcase contains three integers $n, m$ and $k$ ( $2 \le n \le 2 \cdot 10^4$ ; $0 \le m \le 2 \cdot 10^4$ ; $2 \le k \le 10$ ).
The $i$ -th of the next $m$ lines contains a description of a constraint. Each constraint is of one of three following types:
- $1~i~x$ ( $1 \le i \le n$ ; $1 \le x \le k$ ): $a_i$ should not be equal to $x$ ;
- $2~i~j~x$ ( $1 \le i < j \le n$ ; $2 \le x \le 2 \cdot k$ ): $a_i + a_j$ should be less than or equal to $x$ ;
- $3~i~j~x$ ( $1 \le i < j \le n$ ; $2 \le x \le 2 \cdot k$ ): $a_i + a_j$ should be greater than or equal to $x$ .
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^4$ . The sum of $m$ over all testcases doesn't exceed $2 \cdot 10^4$ .
输出格式
For each testcase, determine if there exists a non-decreasing array that satisfies all conditions. If there is no such array, then print -1. Otherwise, print any valid array — $n$ integers from $1$ to $k$ .
输入输出样例
输入 #1
4 4 0 4 2 2 3 3 1 2 3 1 2 2 3 3 2 1 1 1 2 2 3 2 3 2 3 2 5 5 5 3 2 5 7 2 4 5 10 3 4 5 6 3 3 4 7 2 1 5 7
输出 #1
1 2 3 4 1 3 -1 1 2 2 5 5
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted