[Solution] Text Editor Codeforces Solution | Solution Codeforces
You wanted to write a text consisting of lowercase Latin letters. But instead, you have written a text consisting of lowercase Latin letters, and now you want to fix it by obtaining the text from the text .
Initially, the cursor of your text editor is at the end of the text (after its last character). In one move, you can do one of the following actions:
- press the "left" button, so the cursor is moved to the left by one position (or does nothing if it is pointing at the beginning of the text, i. e. before its first character);
- press the "right" button, so the cursor is moved to the right by one position (or does nothing if it is pointing at the end of the text, i. e. after its last character);
- press the "home" button, so the cursor is moved to the beginning of the text (before the first character of the text);
- press the "end" button, so the cursor is moved to the end of the text (after the last character of the text);
- press the "backspace" button, so the character before the cursor is removed from the text (if there is no such character, nothing happens).
Your task is to calculate the minimum number of moves required to obtain the text from the text using the given set of actions, or determine it is impossible to obtain the text from the text .
You have to answer independent test cases.
The first line of the input contains one integer () — the number of test cases. Then test cases follow.
Grass Field Codeforces Solution
Permutation Codeforces Solution
Schedule Management Codeforces Solution
Permutation Restoration Codeforces Solution
Text Editor Codeforces Solution
The first line of the test case contains two integers and () — the length of and the length of , respectively.
The second line of the test case contains the string consisting of lowercase Latin letters.
The third line of the test case contains the string consisting of lowercase Latin letters.
It is guaranteed that the sum of over all test cases does not exceed ().
For each test case, print one integer — the minimum number of moves required to obtain the text from the text using the given set of actions, or -1 if it is impossible to obtain the text from the text in the given test case.
No comments:
Post a Comment