|시간 제한||메모리 제한||제출||정답||맞은 사람||정답 비율|
|2 초||512 MB||4||1||1||25.000%|
Real-time software in the Mars Pathfinder spacecraft suffered from an issue known as priority inversion. One technique to address this issue is to use the Priority Ceiling Protocol.
In this problem, you will simulate the execution of multiple tasks according to this protocol. The tasks share a collection of resources, each of which can be used by only one task at a time. To ensure this, resources must be locked before use and unlocked after use. Each task is defined by a start time, a unique base priority, and a sequence of instructions. Each task also has a current priority, which may change during execution. Instructions come in three types:
After locking a resource, a task is said to own the resource until the task unlocks it. A task will unlock only the owned resource it most recently locked, will not lock a resource it already owns, and will complete with no owned resources.
Each resource has a fixed priority ceiling, which is the highest base priority of any task that contains an instruction to lock that resource.
There is a single processor that executes the tasks. When the processor starts, it initializes its clock to zero and then runs an infinite loop with the following steps:
The Priority Ceiling Protocol defined above has the following properties:
The first line of the input contains two integers t (1 ≤ t ≤ 20), which is the number of tasks, and r (1 ≤ r ≤ 20), which is the number of resources. This is followed by t lines, where the ith of these lines describes task i. The description of a task begins with three integers: the task’s start time s (1 ≤ s ≤ 10 000), its base priority b (1 ≤ b ≤ t), and an integer a (1 ≤ a ≤ 100). A task description is concluded by a sequence of a strings describing the instructions. Each string is a letter (
U) followed by an integer. The string
Cn (1 ≤ n ≤ 100) indicates a sequence of n compute instructions. The strings
Uk (1 ≤ k ≤ r) indicate instructions locking and unlocking resource k respectively.
No two tasks have the same base priority.
For each task, display the time it completes execution, in the same order that the tasks are given in the input.
3 1 50 2 5 C1 L1 C1 U1 C1 1 1 5 C1 L1 C100 U1 C1 70 3 1 C1
106 107 71
3 3 5 3 5 C1 L1 C1 U1 C1 3 2 9 C1 L2 C1 L3 C1 U3 C1 U2 C1 1 1 9 C1 L3 C3 L2 C1 U2 C1 U3 C1
8 15 16