#P9967. [THUPC 2024 初赛] 采矿
[THUPC 2024 初赛] 采矿
Background
"I can't afford a second robot anymore."
"Then hire some people to make up the numbers. Just don't get them killed in there."
Problem Description
You are the owner of a mine.
Your mine has a binary-tree structure with nodes. Node is the ground. For all , node is connected by a tunnel to a shallower node , where , and each same value of appears at most twice. Different nodes in the mine have different productivity and mining difficulty. For node , if you assign a robot to mine there, it produces output per unit time; if you assign a human to mine there, it produces output per unit time. The ground produces no output.
You have one robot, initially located at node . Initially, there are no human workers in your mine.
All tunnels and nodes are very narrow. Each node can hold only one worker (workers include both humans and the robot). Each tunnel can also allow exactly one worker to pass through. At any moment during movement, there can be at most one worker in a tunnel; all other workers must stay on nodes.
You now have plans that must be executed in order. Each plan consists of four phases: preparation, execution, adjustment, and mining.
In the preparation phase, humans may move arbitrarily as long as the above movement rules are satisfied, but they cannot enter or leave the mine (a worker in the mine reaching node is not considered leaving the mine), because you are watching them. There is no limit on the order or number of moves. The robot cannot move.
In the execution phase, different plans require different actions. There are types in total:
- The robot may only move along tunnels toward a shallower direction, and it must pass through at least one tunnel. Humans cannot move.
- The robot may only move along tunnels toward a deeper direction, and it must pass through at least one tunnel. Humans cannot move.
- Make one human enter the mine from node (this means that at the start of this phase, there must be no worker on node ). Besides this, no worker may move.
- Make one human leave the mine via node (this means that at the start of this phase, there must be a human on node ). Besides this, no worker may move.
In the adjustment phase, the restrictions are the same as in the preparation phase. Humans may move arbitrarily as long as the movement rules are satisfied, but they cannot enter or leave the mine. There is no limit on the order or number of moves. The robot cannot move.
In the mining phase, all workers mine for one unit of time. Every non-ground node that has a worker produces output according to the type of worker on that node. Nodes without workers produce no output. The output of this plan is the sum of the outputs of all nodes.
Compute the maximum possible total output summed over all plans after executing all plans in order.
Input Format
The first line contains three positive integers .
The second line contains integers, where the -th one denotes .
The third line contains integers, where the -th one denotes .
The fourth line contains integers, where the -th one denotes .
The next lines each contain one integer indicating the type of a plan, where the -th integer denotes the -th plan:
1means the first type: move the robot in a shallower direction;2means the second type: move the robot in a deeper direction;3means the third type: send one human into the mine from node ;4means the fourth type: move one human out of the mine via node .
Output Format
If it is impossible to complete your plans no matter what, output one line No solution.. Otherwise, output one line with one integer, the maximum total output.
5 6 4
1 1 3 3
15 9 7 1
4 2 8 6
3
3
1
2
2
4
91
Hint
Sample #1 Explanation
One optimal solution is as follows (some phases with no movement are omitted):
Adjustment phase of the first plan: move the human just sent into node twice to node .
Mining phase of the first plan: the robot output is , and the human output is .
Adjustment phase of the second plan: move the human just sent into node to node .
Mining phase of the second plan: the robot output is , and the human output is .
Execution phase of the third plan: move the robot to node .
Adjustment phase of the third plan: move one human from node to node .
Mining phase of the third plan: the robot output is , and the human output is .
Preparation phase of the fourth plan: move one human from node to node .
Execution phase of the fourth plan: move the robot to node .
Mining phase of the fourth plan: the robot output is , and the human output is .
Execution phase of the fifth plan: move the robot to node .
Mining phase of the fifth plan: the robot output is , and the human output is .
Preparation phase of the sixth plan: move one human from node to node .
Mining phase of the sixth plan: the robot output is , and the human output is .
The total output is .
Subtasks
It is guaranteed that , , and .
It is guaranteed that and .
It is guaranteed that each same value of appears at most twice.
Problem Usage Agreement
From the THUPC2024 (Tsinghua University Programming Contest and Collegiate Invitational Contest 2024) preliminary round.
In the following, "this repository" refers to the official THUPC2024 preliminary repository (https://github.com/ckw20/thupc2024_pre_public).
-
Any organization or individual may use or redistribute the problems in this repository for free.
-
When using the problems in this repository, any organization or individual should do so free of charge and publicly. It is strictly forbidden to use these problems for profit or to add special permissions to these problems.
-
If possible, when using the problems in this repository, please also provide how to obtain resources such as the testdata, reference solution, and editorial. Otherwise, please attach the GitHub link of this repository.
Translated by ChatGPT 5