Editorial for TLE '17 Contest 4 P2 - Microwave Buttons


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Author: ZQFMGB12

Since there are not a lot of possible combinations of time, we can simply iterate through every possible 2-digit hour, minute, and second combination. For each combination, check if the numbers can be constructed using available buttons, and convert the time to seconds. Compare the difference in seconds with the desired time and output the time with the smallest difference. Be wary that single digit numbers have a leading zero.

Alternatively, one can do some annoying casework or some more optimal brute force.

Time Complexity: \mathcal{O}(1) (approximately 1 million iterations)


Comments

There are no comments at the moment.