#P3587. [POI 2015 R2] 项链分割 Necklace partition
[POI 2015 R2] 项链分割 Necklace partition
Description
There is a circular necklace with beads, each bead being one of colors. Bead is adjacent to beads and , and bead is also adjacent to bead .
Cut the necklace at two positions to split it into two linear segments. For each color, all beads of that color must appear in exactly one of the two segments.
Compute the number of valid ways (it is guaranteed that at least one exists), and the minimum absolute difference between the lengths of the two segments.
Input Format
The first line contains (). Colors are labeled from to .
The next integers, in order, give the color of each bead. (It is guaranteed that each of the colors appears at least once.)
Output Format
Output one line with two integers: the number of valid ways, and the minimum absolute difference between the lengths of the two segments.
9 5
2 5 3 2 2 4 1 1 3
4 3
Hint
【Sample Explanation】
Among the four ways, the shorter segment is respectively , , , . The minimum difference is .
Original title: Podział naszyjnika.
Translated by ChatGPT 5
京公网安备 11011102002149号