Grace is a biologist working in a bioinformatics firm in Singapore. As part of her job, she analyses the DNA sequences of various organisms. A DNA sequence is defined as a string consisting of characters "A", "T", and "C". Note that in this task DNA sequences do not contain character "G".
We define a mutation to be an operation on a DNA sequence where two elements of the sequence are swapped. For example a single mutation can transform "ACTA" into "AATC" by swapping the highlighted characters "A" and "C".
The mutation distance between two sequences is the minimum number of mutations required to transform one sequence into the other, or
Grace is analysing two DNA sequences
Implementation Details
You should implement the following procedures:
void init(std::string a, std::string b)
, : strings of length , describing the two DNA sequences to be analysed.- This procedure is called exactly once, before any calls to
get_distance
.
int get_distance(int x, int y)
, : starting and ending indices of the substrings to be analysed.- The procedure should return the mutation distance between substrings
and . - This procedure is called exactly
times.
Example
Consider the following call:
init("ATACAT", "ACTATA")
Let's say the grader calls get_distance(1, 3)
. This call should return the mutation distance between
Therefore, this call should return
Let's say the grader calls get_distance(4, 5)
. This call should return the mutation distance between sequences "AT" and "TA". "AT" can be transformed into "TA" through a single mutation, and clearly at least one mutation is required.
Therefore, this call should return
Finally, let's say the grader calls get_distance(3, 5)
. Since there is no way for the sequence "CAT" to be transformed into "ATA" via any sequence of mutations, this call should return
Constraints
- Each character of
and is one of "A", "T", and "C".
Subtasks
- (
points) - (
points) , each character of and is either "A" or "T". - (
points) each character of and is either "A" or "T". - (
points) - (
points) No additional constraints.
Sample Grader
The sample grader reads the input in the following format:
- line
: - line
: - line
: - line
: for the -th call toget_distance
.
The sample grader prints your answers in the following format:
- line
: the return value of the -th call toget_distance
.
Attachment Package
The sample grader and sample test cases are available here: dna.zip.
Comments