Tokitsukaze and Two Colorful Tapes Codeforces Solution | Codeforces Problem Solution 2022
Tokitsukaze has two colorful tapes. There are distinct colors, numbered through , and each color appears exactly once on each of the two tapes. Denote the color of the -th position of the first tape as , and the color of the -th position of the second tape as .
Now Tokitsukaze wants to select each color an integer value from to , distinct for all the colors. After that she will put down the color values in each colored position on the tapes. Denote the number of the -th position of the first tape as , and the number of the -th position of the second tape as .
For example, for the above picture, assuming that the color red has value (), it appears at the -st position of the first tape and the -rd position of the second tape, so .
[Solution] Tokitsukaze and Good 01-String
Tokitsukaze and Two Colorful Tapes Codeforces Solution
Tokitsukaze and Permutations Codeforces Solution
Note that each color from to should have a distinct value, and the same color which appears in both tapes has the same value.
After labeling each color, the beauty of the two tapes is calculated as
Please help Tokitsukaze to find the highest possible beauty.
The first contains a single positive integer () — the number of test cases.
For each test case, the first line contains a single integer () — the number of colors.
The second line contains integers () — the color of each position of the first tape. It is guaranteed that is a permutation.
The third line contains integers () — the color of each position of the second tape. It is guaranteed that is a permutation.
It is guaranteed that the sum of over all test cases does not exceed .
For each test case, print a single integer — the highest possible beauty.
Join Now for Solution:-
No comments:
Post a Comment