| <p> | |
| As an experienced boomerangist, you take great pride in your trusty boomerang, and you'd like to be able to show it off! Unfortunately, it doesn't look quite right yet... | |
| </p> | |
| <p> | |
| Like all boomerangs, yours is symmetrical in shape, with two <strong>N</strong> millimetre-long halves. However, what's not necessarily symmetrical is its paint job | |
| — each millimetre-long section of each half has been painted some color. There are 26 possible colors, represented by uppercase letters ("A" to "Z"), | |
| and the <strong>i</strong>th section of the left half (counting from the left end) has color <strong>A<sub>i</sub></strong>, | |
| while the <strong>i</strong>th section of the right half (counting from the right end) has color <strong>B<sub>i</sub></strong>. | |
| You'd like your boomerang to be completely symmetrical (which is the case when the <strong>i</strong>th section in the left half has the same color as the | |
| <strong>i</strong>th section in the right half, for all 1 ≤ <strong>i</strong> ≤ <strong>N</strong>) as soon as possible! | |
| </p> | |
| <p> | |
| To that end, you're enlisting the help of your two best friends, Jack and Jill, to repaint the left half of your boomerang until it matches the right half. | |
| Every second, Jack may paint over a "prefix" of the left half with a solid color, while Jill may simultaneously paint over a disjoint "suffix". | |
| In other words, every second, Jack and Jill will each select a color (from "A" to "Z"), | |
| Jack will select a value <strong>x</strong> (0 ≤ <strong>x</strong> ≤ <strong>N</strong>), | |
| and Jill will select a value <strong>y</strong> (0 ≤ <strong>y</strong> ≤ <strong>N - x</strong>). | |
| Then, Jack will repaint the first <strong>x</strong> sections of the left half of the boomerang with his color, | |
| while Jill will repaint the last <strong>y</strong> sections of the left half of the boomerang with her color. | |
| Painting over a section completely overwrites its previous color. | |
| </p> | |
| <p> | |
| What's the minimum amount of time (in seconds) it can take Jack and Jill to make your boomerang completely symmetrical? | |
| </p> | |
| <h3>Input</h3> | |
| <p> | |
| Input begins with an integer <strong>T</strong>, the number of boomerangs you want to decorate. | |
| For each boomerang, there is first a line containing the integer <strong>N</strong>, then two lines that each contain a string of length <strong>N</strong>. | |
| The <strong>i</strong>th character of the second line is <strong>A<sub>i</sub></strong>. | |
| The <strong>i</strong>th character of the third line is <strong>B<sub>i</sub></strong>. | |
| </p> | |
| <h3>Output</h3> | |
| <p> | |
| For the <strong>i</strong>th boomerang, print a line containing "Case #<strong>i</strong>: " followed by | |
| the minimum number of seconds it will take Jack and Jill to make your boomerang's paint job symmetrical. | |
| </p> | |
| <h3>Constraints</h3> | |
| <p> | |
| 1 ≤ <strong>T</strong> ≤ 75 <br /> | |
| 1 ≤ <strong>N</strong> ≤ 100,000 <br /> | |
| </p> | |
| <h3>Explanation of Sample</h3> | |
| <p> | |
| The first boomerang is already symmetrical, so no work needs to be done. The second boomerang can be made symmetrical in 1 second. Jack will cover the first millimetre with 'C', and Jill will cover the third millimetre with 'A'. The third boomerang takes 2 seconds to paint. One possible solution is for Jack to paint the first two millimetres with 'A' and then the first millimetre with 'B'. | |
| </p> | |