Logo
(追記) (追記ここまで)

34742번 - Keep Fighting 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
0.5 초 2048 MB65583.333%

문제

Bob is playing a card game where he must defeat a monster. Before the game starts, Bob’s power is set to $P,ドル the monster’s health is set to $H,ドル and Bob receives a deck of $N$ cards in his hands.

Each card in the deck belongs to one of the following types:

  • Multiply: a card of this type has a number $X$ written on it. Playing it multiplies Bob’s current power by $X$.
  • Add: a card of this type also has a number $Y$ written on it. Playing it increases Bob’s current power by $Y$.
  • Attack: a card of this type allows Bob to attack the monster. Playing it reduces the monster’s current health by Bob’s current power.

The game is played in turns. In each turn, Bob must play exactly one card from his hand, after which the card is moved to a discard pile. If Bob has no cards left in his hand at the end of a turn, he retrieves all cards from the discard pile and can use them again in any order.

The monster is beaten as soon as its health reaches 0ドル$ or less. Is it possible for Bob to beat the monster? If so, what is the minimum number of turns required?

입력

The first line contains three integers $N$ (1ドル ≤ N ≤ 50$), $P$ (0ドル ≤ P ≤ 10^9$) and $H$ (1ドル ≤ H ≤ 10^9$), indicating respectively the number of cards in the deck, Bob’s initial power and the monster’s initial health.

Each of the next $N$ lines describes a card. The content of the line depends on the type of the card, as follows:

  • Multiply: the line contains the character “*” (asterisk) and an integer $X$ (1ドル ≤ X ≤ 10^9$), representing the multiply factor provided by the card.
  • Add: the line contains the character “+” (plus sign) and an integer $Y$ (1ドル ≤ Y ≤ 10^9$), indicating the increment provided by the card.
  • Attack: the line contains the character “!” (exclamation mark).

출력

Output a single line with an integer indicating the minimum number of turns required to beat the monster, or the character “*” (asterisk) if it is impossible to beat the monster.

제한

예제 입력 1

3 0 20
* 2
!
+ 5

예제 출력 1

4

To beat the monster in 4ドル$ turns, Bob can play as follows:

  1. Bob plays the + 5ドル$ card, so his power becomes 5ドル$.
  2. Bob plays the * 2ドル$ card, so his power becomes 10ドル$.
  3. Bob plays the ! card, so the monster’s health becomes 10ドル$. Since now Bob has no cards in his hands, all three cards go back to him.
  4. Bob plays the ! card, so the monster’s health becomes 0ドル,ドル and the monster is beaten.

예제 입력 2

1 0 1
!

예제 출력 2

*

예제 입력 3

1 1 1
+ 1

예제 출력 3

*

노트

출처

ICPC > Regionals > Latin America > Latin America Championship > The 2025 ICPC Latin America Championship K번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /