A10512 | Captain America
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Steve Rogers is fascinated with new vibranium shields S.H.I.E.L.D gave him. They're all uncolored. There are $n$ shields in total, the $i$ -th shield is located at point $(x_{i},y_{i})$ of the coordinate plane. It's possible that two or more shields share the same location.
Steve wants to paint all these shields. He paints each shield in either red or blue. Painting a shield in red costs $r$ dollars while painting it in blue costs $b$ dollars.
Additionally, there are $m$ constraints Steve wants to be satisfied. The $i$ -th constraint is provided by three integers $t_{i}$ , $l_{i}$ and $d_{i}$ :
- If $t_{i}=1$ , then the absolute difference between the number of red and blue shields on line $x=l_{i}$ should not exceed $d_{i}$ .
- If $t_{i}=2$ , then the absolute difference between the number of red and blue shields on line $y=l_{i}$ should not exceed $d_{i}$ .
Steve gave you the task of finding the painting that satisfies all the condition and the total cost is minimum.
Steve wants to paint all these shields. He paints each shield in either red or blue. Painting a shield in red costs $r$ dollars while painting it in blue costs $b$ dollars.
Additionally, there are $m$ constraints Steve wants to be satisfied. The $i$ -th constraint is provided by three integers $t_{i}$ , $l_{i}$ and $d_{i}$ :
- If $t_{i}=1$ , then the absolute difference between the number of red and blue shields on line $x=l_{i}$ should not exceed $d_{i}$ .
- If $t_{i}=2$ , then the absolute difference between the number of red and blue shields on line $y=l_{i}$ should not exceed $d_{i}$ .
Steve gave you the task of finding the painting that satisfies all the condition and the total cost is minimum.
输入格式
The first line of the input contains two integers $n$ and $m$ ( $1<=n,m<=100000$ ) — the number of shields and the number of constraints respectively.
The second line contains two integers $r$ and $b$ ( $1<=r,b<=10^{9}$ ).
The next $n$ lines contain the shields coordinates. The $i$ -th of these lines contains two integers $x_{i}$ and $y_{i}$ ( $1<=x_{i},y_{i}<=10^{9}$ ).
The next $m$ lines contain the constrains. The $j$ -th of these lines contains three integers $t_{j}$ , $l_{j}$ and $d_{j}$ ( $1<=t_{j}<=2,1<=l_{j}<=10^{9},0<=d_{j}<=n$ ).
The second line contains two integers $r$ and $b$ ( $1<=r,b<=10^{9}$ ).
The next $n$ lines contain the shields coordinates. The $i$ -th of these lines contains two integers $x_{i}$ and $y_{i}$ ( $1<=x_{i},y_{i}<=10^{9}$ ).
The next $m$ lines contain the constrains. The $j$ -th of these lines contains three integers $t_{j}$ , $l_{j}$ and $d_{j}$ ( $1<=t_{j}<=2,1<=l_{j}<=10^{9},0<=d_{j}<=n$ ).
输出格式
If satisfying all the constraints is impossible print -1 in first and only line of the output.
Otherwise, print the minimum total cost in the first line of output. In the second line print a string of length $n$ consisting of letters 'r' and 'b' only. The $i$ -th character should be 'r' if the $i$ -th shield should be painted red in the optimal answer and 'b' if it should be painted blue. The cost of painting shields in these colors should be equal the minimum cost you printed on the first line.
If there exist more than one optimal solution, print any of them.
Otherwise, print the minimum total cost in the first line of output. In the second line print a string of length $n$ consisting of letters 'r' and 'b' only. The $i$ -th character should be 'r' if the $i$ -th shield should be painted red in the optimal answer and 'b' if it should be painted blue. The cost of painting shields in these colors should be equal the minimum cost you printed on the first line.
If there exist more than one optimal solution, print any of them.
输入输出样例
输入 #1
5 6 8 3 2 10 1 5 9 10 9 10 2 8 1 9 1 1 2 1 2 10 3 2 10 2 1 1 1 2 5 2
输出 #1
25 rbrbb
输入 #2
4 4 7 3 10 3 9 8 10 3 2 8 2 8 0 2 8 0 1 2 0 1 9 0
输出 #2
-1
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted