https://www.spoj.com/problems/ADAMATCH/
How to solve this problem?
| # | User | Rating |
|---|---|---|
| 1 | Kevin114514 | 3722 |
| 2 | Benq | 3676 |
| 3 | jiangly | 3640 |
| 4 | turmax | 3450 |
| 5 | tourist | 3408 |
| 6 | strapple | 3360 |
| 7 | Um_nik | 3354 |
| 8 | squareOf105 | 3348 |
| 9 | maroonrk | 3196 |
| 10 | idontwannadothis…e | 3191 |
| # | User | Contrib. |
|---|---|---|
| 1 | maroonrk | 153 |
| 2 | Qingyu | 152 |
| 3 | nik_exists | 151 |
| 4 | maspy | 147 |
| 4 | AmShZ | 147 |
| 6 | Um_nik | 144 |
| 7 | Errichto | 139 |
| 8 | adamant | 135 |
| 9 | BledDest | 134 |
| 10 | AksLolCoding | 132 |
https://www.spoj.com/problems/ADAMATCH/
How to solve this problem?
| Name |
|---|



This problem can be solved in a similar way as MAXMATCH.
You can first find maximum matching of the two strings by keeping s fixed and varying r. To achieve that you can construct polynomial for each of the different character, by raising x to the powers of indexes in
sand to negative of powers of index inr. For example considers = ATCAAAr = ACAANow for character
A, and s you will construct polynomial x0 + x3 + x4 + x5And for character
A, and r you will construct x0 + x - 2 + x - 3.Now when you multiply them, the coefficient of xk will represent number of matching indexes for
Ain kth shift.You can just sum that over all four characters and answer will
res.size() - maximum_matchingBut, how we will multiply them? FFT multiplies polynomials with non-zero powers of x.