#P8521. [IOI 2021] 修改 DNA
[IOI 2021] 修改 DNA
Background
Abuse of the judging system for this problem will result in an account ban.
Due to technical limitations, please do not submit this problem using the C++ 14 (GCC 9) language option.
This is an interactive problem. You only need to implement the functions required in the code.
Your code does not need to include any extra header files, and you do not need to implement the main function.
Problem Description
Grace is a biologist working at a bioinformatics company in Singapore. Part of her job is to analyze DNA sequences of different organisms. A DNA sequence is a string containing the characters A, T, and C. Note that in this problem, DNA sequences do not contain the character G.
A mutation is defined as swapping the positions of two elements in a DNA sequence. For example, by swapping the bold characters A and C, one mutation can turn ACTA into AATC.
The mutation distance between two sequences is the minimum number of mutations needed to transform one sequence into the other. If it is impossible to transform one sequence into the other using mutations, then the mutation distance between the two sequences is .
Grace is analyzing two DNA sequences and , each consisting of elements, indexed from to . Your task is to help Grace answer queries of the following form: what is the mutation distance between the substrings and ? Here, the substring of a DNA sequence is defined as the contiguous sequence of characters of with indices from to (including and ). That is, is the sequence .
Input Format
You need to implement the following functions:
void init(string a, string b)
- : strings of length , representing the two DNA sequences to be analyzed.
This function is called exactly once, and it is called before any call to
get_distance.
int get_distance(int x, int y)
- : the starting and ending indices of the substring to be analyzed. This function should return the mutation distance between the substrings and . This function is called exactly times.
6 3
ATACAT
ACTATA
1 3
4 5
3 5
2
1
-1
Hint
For all testdata:
- Each character of and is one of A, T, and C.
| Subtask | Points | Special constraints |
|---|---|---|
| , , each character of and is A or T | ||
| each character of and is A or T | ||
| , | ||
| no additional constraints |
Sample Explanation
If the judging program calls get_distance(1, 3), then this call should return the mutation distance between and (that is, the sequences TAC and CTA). It takes mutations to turn TAC into CTA: TAC CAT, and then CAT CTA. It is impossible to complete this transformation with fewer than mutations.
Therefore, this call should return .
If the judging program calls get_distance(4, 5), then this call should return the mutation distance between the sequences AT and TA. With one mutation, AT can be transformed into TA, and clearly at least one is required.
Therefore, this call should return .
Finally, if the judging program calls get_distance(3, 5), since it is impossible to transform the sequence CAT into ATA using mutations, this call should return .
Translated by ChatGPT 5