No.2691 Longest Infection Sequence
タグ : / 解いたユーザー数 189
作問者 :
hibit_at
/ テスター :
MM
👑 Problem Statement
hibit, an evil doctor, is in charge of patients with the following breakdown.
- $A$ people whose blood type is type A
- $B$ people whose blood type is type B
- $O$ people whose blood type is type O
- $W$ people whose blood type is type AB
Blood types have the following properties.
- A person of type A can donate blood only to people of type A or type AB
- A person of type B can donate blood only to people of type B or type AB
- A person of type O can donate blood to everyone
- A person of type AB can donate blood only to people of type AB
Since hibit is an evil doctor, he wants to infect as many of the patients as possible with the "HB virus".
First, he performs the following step exactly $1$ time.
- Inject the virus into some person. That person becomes infected
After that, he performs the following step any number of times (possibly $0$ times).
- Transfuse blood from one person to another person (only if their blood types are compatible)
- If the donor is infected, the recipient also becomes infected
- Each person can give a transfusion (be a donor) only $1$ time
Output the maximum number of patients who become infected.
Input
$A\ B\ O\ W$
- All inputs are integers
- $0 \leq A,B,O,W \leq 10^3$
- There is at least $1$ patient. That is, $(A,B,O,W) \neq (0,0,0,0)$
Output
Output an integer on $1$ line.
Sample
Sample 1
Input
1 1 1 1
Output
3
In this input, there is $1$ person each of types A, B, O, and AB.
- First, inject the virus into the type O person. That person becomes infected.
- The type O person donates blood to the type B person. The type B person becomes infected.
- The type B person donates blood to the type AB person. The type AB person becomes infected.
As a result, the number of infected patients is $3$. Various other routes are possible, but this is the maximum.
Sample 2
Input
3 4 5 6
Output
15
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。