問題一覧 > 通常問題

No.2691 Longest Infection Sequence

レベル : / AI推定難易度 : 159 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 189
作問者 : hibit_at / テスター : MM 👑 seekworser ypww m46bSDt
お気に入りにしたユーザー ProblemId : 9897 / 自分の提出
問題文最終更新日: 2024-03-21 14:29:44
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 423 (Asakatsu Presents 3) (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。