#P7412. [USACO21FEB] Year of the Cow S
[USACO21FEB] Year of the Cow S
Description
Farmer John’s cows are very excited to learn that the Year of the Ox is being celebrated recently. The Year of the Ox is always the cows’ favorite.
We know that in the Chinese calendar, the zodiac animal for each year follows a 12-year cycle: Ox, Tiger, Rabbit, Dragon, Snake, Horse, Goat, Monkey, Rooster, Dog, Pig, Rat, and then back to Ox. A lesser-known fact is that whenever the Year of the Ox arrives, a mysterious time portal opens, allowing the cows to travel through time to any past or future Year of the Ox.
Bessie the cow wants to use the time portal opened this year to visit famous ancestors who lived long ago, where (it seems fitting to express the range of in hexadecimal in the Year of the Ox; equals ).
Unfortunately, too much time travel makes Bessie dizzy, so she wants to travel through the portal at most times (). Please help Bessie find the minimum number of years she must spend to visit all her ancestors and return to the current year, if she uses the portal at most times.
If, in some Year of the Ox, Bessie does not want to use the time portal, she may choose not to. The time portal connects the first day of each Year of the Ox. Therefore, for example, if Bessie goes to some portal year and then waits until the next portal 12 years later, she spends exactly 12 years during that process. Bessie starts her trip on the first day of the current year, so she can time travel immediately. None of Bessie’s ancestors lived in a Year of the Ox.
Input Format
The first line contains and . The next lines contain distinct integers in the range , where each integer represents how many years ago one of Bessie’s ancestors lived.
Output Format
Output the minimum number of years Bessie needs to spend to visit all ancestors and return to the current year.
5 3
101
85
100
46
95
36
Hint
One way for Bessie to visit all ancestors and return within 36 years is as follows:
- Enter the time portal and go back to 48 years ago.
- Wait 12 years, then enter the portal from 36 years ago and go back to 108 years ago.
- Wait 24 years, then enter the portal from 84 years ago and return to the current year.
Problem by: Brian Dean, David Yang.
Translated by ChatGPT 5
京公网安备 11011102002149号