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

34287번 - A=B 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 2048 MB72432052.632%

문제

After hours of playing the hit puzzle game A=B, you've become an expert at transforming strings using substitution rules. In A=B, players are challenged to manipulate strings using a minimalistic programming language that consists solely of substitution instructions of the form 'A=B'. Each instruction replaces occurrences of string 'A' with string 'B', allowing players to solve various problems—from simple character replacements to more complex transformations like multiplying binary numbers. Inspired by the game's elegant simplicity and the power of its single operation, you had an epiphany: "I could totally make this myself!"

With newfound inspiration, you decide to build your own version of the A=B interpreter. Your version will follow a strict sequence of substitution rules, carefully applying them one at a time until the string can't change any further—or until it grows out of control! You decide to include safety limits for memory and time, so your interpreter won't run away in an endless loop.

A=B's interpreter works as follows: first, it reads a starting string, as well as an ordered list of rules to apply. Each rule is a string of the form '$A$=$B$', where $A$ and $B$ are strings of uppercase letters without spaces. They each have at most 255ドル$ characters. Note that $B$ may be empty.

One step of your interpreter consists of finding the first rule, $A$=$B,ドル such that the string $A$ occurs in the current string. Then your interpreter should replace the earliest occurrence of $A$ with $B$ in the current string.

If your interpreter does not find any rule that can be applied, then it should exit and output the current string.

If, after 5ドル,000円$ steps, it is still possible to apply some rule, then your interpreter should output "Time Limit Exceeded" and exit immediately.

If at any point the length of the current string exceeds 255ドル$ characters, your interpreter should immediately output "Memory Limit Exceeded" and exit immediately.

입력

The first line contains the starting string $s$ (1ドル \leq |s| \leq 255$).

The second line contains an integer $n$ (1ドル \leq n \leq 20$), the number of substitution rules.

The next $n$ lines each contain a substitution rule of the form '$A$=$B$' (1ドル \leq |A| \leq 255, 0 \leq |B| \leq 255$), where $A$ and $B$ are strings containing only uppercase English letters.

출력

Print "Time Limit Exceeded" if the interpreter could perform more than 5ドル,000円$ transformations.

Print "Memory Limit Exceeded" if the string length exceeds 255ドル$ characters at any point.

Otherwise, print the value of the final string.

제한

예제 입력 1

CBACAB
3
BA=AB
CA=AC
CB=BC

예제 출력 1

AABBCC

예제 입력 2

A
1
A=AA

예제 출력 2

Memory Limit Exceeded

예제 입력 3

AB
2
AB=C
C=AB

예제 출력 3

Time Limit Exceeded

힌트

출처

School > CS@Mines > CS@Mines HSPC 2025 G번

  • 문제를 만든 사람: Kelly Dance
(追記) (追記ここまで)

출처

대학교 대회

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

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