Long Long Strings
Time limit1sMemory limit512 MB
Decide whether two sequences of insertions and deletions, applied to any sufficiently long string, produce identical results.
- Level
Hard8 of 10
- Topics
- String, Math, Implementation, Simulation
- Solved
- No attempts yet
Problem
To store long DNA sequences, a company built a LongLongString class that holds strings of more than ten billion characters. The class supports two operations.
Ins(p, c): insert the character at position .Del(p): delete the character at position .
A DNA editing program is a sequence of Ins and Del operations. Write a program that decides whether two DNA editing programs are identical, meaning that applying them to any sufficiently long string always gives the same result. For example:
Del(1)Del(2)andDel(3)Del(1)are identical.Del(2)Del(1)andDel(1)Del(2)are different.- A program with no operations and
Ins(1, X)Del(1)are identical. Ins(14, B)Ins(14, A)andIns(14, A)Ins(15, B)are identical.Ins(14, A)Ins(15, B)andIns(14, B)Ins(15, A)are different.
Input
The input holds two DNA editing programs. Each program has between 0 and 2,000 operations, one operation per line. The first character of a line is D for a Del operation, I for an Ins operation, or E for the end of that program.
A D line holds D, a space, and the position of the character to delete. The position is an integer between 1 and . Every character after the deleted one moves one position lower.
An I line holds I, a space, the position where the new character goes, another space, and the character itself, which is an uppercase letter. The character already at that position and everything after it move one position higher.
Output
Print 0 on a single line if the two programs are identical, and 1 otherwise.